improve hashtag parser

This commit is contained in:
Ren Amamiya
2023-09-01 18:26:22 +07:00
parent e6d35bc635
commit 28939d1733
4 changed files with 30 additions and 11 deletions

View File

@@ -62,9 +62,12 @@ export function parser(event: NDKEvent) {
// parse hashtag
const hashtags = content.parsed.split(/\s/gm).filter((s) => s.startsWith('#'));
hashtags?.forEach((tag) => {
content.parsed = content.parsed.replace(tag, ` ~tag-${tag}~ `);
});
if (hashtags) {
const uniqTags = new Set(hashtags);
uniqTags.forEach((tag) => {
content.parsed = content.parsed.replaceAll(tag, `~tag-${tag}~`);
});
}
return content;
}