Skip to content

How to stop tokenizer after specific token? #2532

Answered by UziTech
epszaw asked this question in Q&A
Discussion options

You must be logged in to vote

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],

Replies: 1 comment 4 replies

Comment options

You must be logged in to vote
4 replies
@epszaw
Comment options

@calculuschild
Comment options

@UziTech
Comment options

@epszaw
Comment options

Answer selected by epszaw
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants