From 7d28744234a2fa61211a03a8069363f4d4d69296 Mon Sep 17 00:00:00 2001 From: Lim Chee Aun Date: Sat, 16 Sep 2023 14:47:35 +0800 Subject: [PATCH] Fix some links have same class names from the app itself Srsly need to sanitize the HTML one day --- src/utils/enhance-content.js | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/utils/enhance-content.js b/src/utils/enhance-content.js index 0584ee26..9ccc110a 100644 --- a/src/utils/enhance-content.js +++ b/src/utils/enhance-content.js @@ -10,15 +10,26 @@ function enhanceContent(content, opts = {}) { const hasLink = / { link.setAttribute('target', '_blank'); }); + + // Remove all classes except `u-url`, `mention`, `hashtag` + const links = Array.from(dom.querySelectorAll('a[class]')); + const whitelistClasses = ['u-url', 'mention', 'hashtag']; + links.forEach((link) => { + link.classList.forEach((c) => { + if (!whitelistClasses.includes(c)) { + link.classList.remove(c); + } + }); + }); } // Add 'has-url-text' to all links that contains a url