1
Fork 0
mirror of https://github.com/glassflame/glassflame.github.io.git synced 2024-11-29 03:24:25 +00:00

Add initial support for hashtags

This commit is contained in:
Steffo 2023-10-19 12:38:56 +02:00
parent 6bd681d47e
commit 2aab74553a

View file

@ -15,7 +15,6 @@ const marked = new Marked({
}, },
tokenizer(src, tokens) { tokenizer(src, tokens) {
const match = src.match(/^\[\[([^|\]]+)(?:\|([^\]]+))?]]/) const match = src.match(/^\[\[([^|\]]+)(?:\|([^\]]+))?]]/)
console.debug("Is this a wikilink?", src, tokens, match)
if(match) { if(match) {
return { return {
type: "wikilink", type: "wikilink",
@ -28,6 +27,26 @@ const marked = new Marked({
renderer(token) { renderer(token) {
return `<abbr title="${token.target}">${token.display ?? token.target}</abbr>` return `<abbr title="${token.target}">${token.display ?? token.target}</abbr>`
}, },
},
{
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 `<abbr title="#${token.tag}">#${token.tag}</abbr>`
}
} }
] ]
}) })