Added mentions to the markdown preview

This commit is contained in:
Michael House 2022-06-06 06:09:42 -05:00
parent 12b790dfd7
commit e63a021c61

View file

@ -29,6 +29,30 @@ marked.use({
const content = this.parser.parseInline(token.tokens);
return `<span class="spoiler">${content}</span>`;
}
},
{
name: 'mention',
level: 'inline',
start: function(src){
const match = src.match(/@[a-zA-Z0-9_\-]+/);
return match != null ? match.index : -1;
},
tokenizer: function(src) {
const rule = /^@[a-zA-Z0-9_\-]+/;
const match = rule.exec(src);
if(match){
return {
type: 'mention',
raw: match[0],
text: match[0].trim().slice(1),
tokens: []
};
}
},
renderer(token) {
const u = token.raw;
return `<a href="/${u}"><img src="/${u}/pic" class="pp20"> ${u}</a>`;
}
}
]
});