From cebb9fbdff6aeb95c67fd7f74872aa5badf022e4 Mon Sep 17 00:00:00 2001 From: G1org1owo Date: Tue, 8 Apr 2025 23:37:53 +0200 Subject: [PATCH] client/markdown: add tag to show favicon alongside URL --- client/html/help_comments.tpl | 4 ++++ client/js/util/markdown.js | 11 +++++++++++ 2 files changed, 15 insertions(+) diff --git a/client/html/help_comments.tpl b/client/html/help_comments.tpl index 6ba7e9f8..bd3a6bea 100644 --- a/client/html/help_comments.tpl +++ b/client/html/help_comments.tpl @@ -26,6 +26,10 @@ [sjis](´・ω・`)[/sjis] adds SJIS art + + [icon]https://youtube.com[/icon] + adds the site icon next to the link + diff --git a/client/js/util/markdown.js b/client/js/util/markdown.js index e71e3263..da7f678b 100644 --- a/client/js/util/markdown.js +++ b/client/js/util/markdown.js @@ -110,6 +110,15 @@ class StrikeThroughWrapper extends BaseMarkdownWrapper { } } +class FaviconWrapper extends BaseMarkdownWrapper { + preprocess(text) { + return text.replace( + /\[icon\]((?:[^\[]|\[(?!\/?icon\]))+)\[\/icon\]/gi, + "[![$1](https://www.google.com/s2/favicons?domain=$1)]($1) $1" + ); + } +} + function createRenderer() { function sanitize(str) { return str.replace(/&<"/g, (m) => { @@ -155,6 +164,7 @@ function formatMarkdown(text) { new SpoilersWrapper(), new SmallWrapper(), new StrikeThroughWrapper(), + new FaviconWrapper(), ]; for (let wrapper of wrappers) { text = wrapper.preprocess(text); @@ -181,6 +191,7 @@ function formatInlineMarkdown(text) { new SpoilersWrapper(), new SmallWrapper(), new StrikeThroughWrapper(), + new FaviconWrapper(), ]; for (let wrapper of wrappers) { text = wrapper.preprocess(text);