Skip to content

Commit

Permalink
feat: links in console
Browse files Browse the repository at this point in the history
Signed-off-by: Evan Song <[email protected]>
  • Loading branch information
ferothefox committed Oct 18, 2024
1 parent 23da73f commit 46ce5ff
Showing 1 changed file with 26 additions and 7 deletions.
33 changes: 26 additions & 7 deletions apps/frontend/src/components/ui/servers/LogParser.vue
Original file line number Diff line number Diff line change
Expand Up @@ -37,19 +37,34 @@ const convert = new Convert({
fg: "#FFF",
bg: "#000",
newline: false,
escapeXML: false,
escapeXML: true,
stream: false,
colors,
});
const parsedLog = computed(() => {
return convert.toHtml(props.log);
});
const urlRegex = /https?:\/\/[^\s]+/g;
const usernameRegex = /&lt;([^&]+)&gt;/g;
const sanitizedLog = computed(() => {
return DOMPurify.sanitize(parsedLog.value, {
ALLOWED_TAGS: ["span"],
ALLOWED_ATTR: ["style"],
let html = convert.toHtml(props.log);
html = html.replace(
urlRegex,
(url) =>
`<a style="color:var(--color-link);text-decoration:underline;" href="${url}" target="_blank" rel="noopener noreferrer">${url}</a>`,
);
html = html.replace(
usernameRegex,
(_, username) => `<span class="minecraft-username">&lt;${username}&gt;</span>`,
);
return DOMPurify.sanitize(html, {
ALLOWED_TAGS: ["span", "a"],
ALLOWED_ATTR: ["style", "href", "target", "rel", "class"],
ADD_ATTR: ["target"],
RETURN_TRUSTED_TYPE: true,
USE_PROFILES: { html: true },
});
});
</script>
Expand All @@ -66,4 +81,8 @@ html.dark-mode .parsed-log:hover {
html.oled-mode .parsed-log:hover {
background-color: #333;
}
.minecraft-username {
font-weight: bold;
}
</style>

0 comments on commit 46ce5ff

Please sign in to comment.