#299 Auto link tags in notes to a search for all notes with that tag
authorAdam Dullage <redacted>
Tue, 1 Apr 2025 19:43:09 +0000 (20:43 +0100)
committerAdam Dullage <redacted>
Tue, 1 Apr 2025 19:43:09 +0000 (20:43 +0100)
client/components/toastui/extendedAutolinks.js

index 453c031737a7f82dffa3e63ec88dc747cf0fa273..3a7510ebc96fdf39f3eee99486fdc4cfe716eac9 100644 (file)
@@ -89,11 +89,28 @@ function parseWikiLink(source) {
   return null;
 }
 
+function parseTagLink(source) {
+    const matched = source.matchAll(/(?:^|\s)(#[a-zA-Z0-9_-]+)(?=\s|$)/g);
+    if (matched) {
+      return Array.from(matched).map((match) => {
+        const text = match[1];
+        return {
+          text,
+          range: [match.index + match[0].indexOf(text), match.index + match[0].indexOf(text) + text.length - 1],
+          url: `${router.resolve({ name: "search", query: { term: text } }).href}`,
+        };
+      });
+    }
+  
+    return null;
+  }
+
 function extendedAutolinks(source) {
   return [
     ...parseUrlLink(source),
     ...parseEmailLink(source),
     ...parseWikiLink(source),
+    ...parseTagLink(source),
   ].sort((a, b) => a.range[0] - b.range[0]);
 }
 
git clone https://git.99rst.org/PROJECT