From 55980597154f17ff49e6d9d9a541d75bb0103235 Mon Sep 17 00:00:00 2001 From: Lim Chee Aun <cheeaun@gmail.com> Date: Fri, 14 Apr 2023 21:02:29 +0800 Subject: [PATCH] Spanify un-spanned mentions --- src/utils/enhance-content.js | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/utils/enhance-content.js b/src/utils/enhance-content.js index fe30f50f..55d3bbdc 100644 --- a/src/utils/enhance-content.js +++ b/src/utils/enhance-content.js @@ -15,6 +15,21 @@ function enhanceContent(content, opts = {}) { link.setAttribute('target', '_blank'); }); + // Spanify un-spanned mentions + const mentionLinks = Array.from(dom.querySelectorAll('a[href].mention')); + mentionLinks.forEach((link) => { + if (link.querySelector('*')) { + return; + } + const text = link.innerText; + // If text looks like @username@domain, then it's a mention + if (/^@[^@]+@[^@]+$/g.test(text)) { + // Only show @username + const username = text.split('@')[1]; + link.innerHTML = `@<span>${username}</span>`; + } + }); + // EMOJIS // ====== // Convert :shortcode: to <img />