Fix double ## and scan all links instead

This commit is contained in:
Lim Chee Aun 2023-04-23 09:02:19 +08:00
parent 8d42e33f71
commit 861a596d4e

View file

@ -18,9 +18,7 @@ function enhanceContent(content, opts = {}) {
});
// Spanify un-spanned mentions
const notMentionLinks = Array.from(
dom.querySelectorAll('a[href]:not(.mention)'),
);
const notMentionLinks = Array.from(dom.querySelectorAll('a[href]'));
notMentionLinks.forEach((link) => {
const text = link.innerText.trim();
const hasChildren = link.querySelector('*');
@ -33,7 +31,7 @@ function enhanceContent(content, opts = {}) {
}
// If text looks like #hashtag, then it's a hashtag
if (/^#[^#]+$/g.test(text)) {
if (!hasChildren) link.innerHTML = `#<span>${text}</span>`;
if (!hasChildren) link.innerHTML = `#<span>${text.slice(1)}</span>`;
link.classList.add('mention', 'hashtag');
}
});