Repository navigation
Replies: 1 comment
|
Marked lets an inline extension define its own delimiter; it doesn't reserve a universal syntax for every possible custom tag. For a spoiler, Here is a minimal plain-text spoiler token: import { Marked } from 'marked';
const escape = text => text.replace(/[&<>"']/g, char => ({
'&': '&', '<': '<', '>': '>', '"': '"', "'": ''',
}[char]));
const marked = new Marked({
extensions: [{
name: 'spoiler',
level: 'inline',
start(src) { return src.indexOf('||'); },
tokenizer(src) {
const match = /^\|\|([^\n]+?)\|\|/.exec(src);
if (match) return { type: 'spoiler', raw: match[0], text: match[1] };
},
renderer(token) {
return `<span class="spoiler">${escape(token.text)}</span>`;
},
}],
});
console.log(marked.parse('Before ||a secret|| after.'));This produced the spoiler You could use |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
For block tags, it seems the following pattern is the way to go:
What about inline tags - what would be a good markdown-friendly pattern? For example, for "spoiler" that would blur text unless users clicks on it, I could imagine
!!!...!!!but there are not that many special characters left for more tags. The *_=`~ are already taken. Even ! for image. Is there some guideline on how to come up with inline markdown tags?All reactions