From 2aab74553a3cf09663aec3e02021cbc455e0c4a7 Mon Sep 17 00:00:00 2001 From: Stefano Pigozzi Date: Thu, 19 Oct 2023 12:38:56 +0200 Subject: [PATCH] Add initial support for `hashtag`s --- src/page.mjs | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/src/page.mjs b/src/page.mjs index 9312473..2155b4d 100644 --- a/src/page.mjs +++ b/src/page.mjs @@ -15,7 +15,6 @@ const marked = new Marked({ }, tokenizer(src, tokens) { const match = src.match(/^\[\[([^|\]]+)(?:\|([^\]]+))?]]/) - console.debug("Is this a wikilink?", src, tokens, match) if(match) { return { type: "wikilink", @@ -28,6 +27,26 @@ const marked = new Marked({ renderer(token) { return `${token.display ?? token.target}` }, + }, + { + name: "hashtag", + level: "inline", + start(src) { + return src.match(/^#/)?.index + }, + tokenizer(src, tokens) { + const match = src.match(/^#([A-Za-z0-9]+)/) + if(match) { + return { + type: "hashtag", + raw: match[0], + tag: match[1], + } + } + }, + renderer(token) { + return `#${token.tag}` + } } ] })