Added mentions to the markdown preview
This commit is contained in:
parent
12b790dfd7
commit
e63a021c61
1 changed files with 24 additions and 0 deletions
|
@ -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>`;
|
||||
}
|
||||
}
|
||||
]
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue