-
I'm trying to implement custom expression, like
How I can stop tokenizer after Or how I can skip parsing of the inner variable's part inside brakets? |
Beta Was this translation helpful? Give feedback.
Answered by
UziTech
Jul 12, 2022
Replies: 1 comment 4 replies
-
You can use a custom extension to create your own tokens and render them however you want. Something like: const var = {
name: 'var',
level: 'inline', // Is this a block-level or inline-level tokenizer?
start(src) { return src.indexOf('@var'); }, // Hint to Marked.js to stop and check for a match
tokenizer(src, tokens) {
const rule = /^@var\[(\w+)\]/; // Regex for the complete token, anchor to string start
const match = rule.exec(src);
if (match) {
return { // Token to generate
type: 'var', // Should match "name" above
raw: match[0], // Text to consume from the source
name: match[1], // Additional custom properties
};
}
},
renderer(token) {
return token.raw; // Return the final HTML for this token
}
};
marked.use({extensions: [var]}); |
Beta Was this translation helpful? Give feedback.
4 replies
Answer selected by
epszaw
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You can use a custom extension to create your own tokens and render them however you want.
Something like: