From: Adam Dullage Date: Tue, 1 Apr 2025 19:43:09 +0000 (+0100) Subject: #299 Auto link tags in notes to a search for all notes with that tag X-Git-Url: http://git.99rst.org/?a=commitdiff_plain;h=bd3fa2e51285320c4a31375ddaeb96bf239f89ee;p=flatnotes.git #299 Auto link tags in notes to a search for all notes with that tag --- diff --git a/client/components/toastui/extendedAutolinks.js b/client/components/toastui/extendedAutolinks.js index 453c031..3a7510e 100644 --- a/client/components/toastui/extendedAutolinks.js +++ b/client/components/toastui/extendedAutolinks.js @@ -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]); }