Skip to content
\n

This is the source markdown:

\n
1*\n\n2* suffix\n\n_prefix_ 3*\n\nprefix 4*\n\nprefix 5* suffix
\n

This is the result:
\n\"obrázok\"

\n

It seems to be unable to work if there is text before it. It works if the text is tokenized(like italic or bold) but not if it is plain text.
\nI tried to do additional inline parsing but I cannot prepend the text to my own token so this is not working at all.

","upvoteCount":1,"answerCount":1,"acceptedAnswer":{"@type":"Answer","text":"

ah, this worked:

\n
const rating = {\n  name: 'rating',\n  level: 'inline',\n  start(src) { return src.match(/[1-5]\\*/)?.index; }, <-- no caret\n  tokenizer(src) {\n    const match = src.match(/^([1-5])\\*/); <--- caret\n    if (match) {\n      return {\n        type: 'rating',\n        raw: match[0],\n        rating: parseInt(match[1]),\n      };\n    }\n  }\n};
","upvoteCount":0,"url":"https://github.com/markedjs/marked/discussions/3418#discussioncomment-10367403"}}}
Discussion options

You must be logged in to vote

ah, this worked:

const rating = {
  name: 'rating',
  level: 'inline',
  start(src) { return src.match(/[1-5]\*/)?.index; }, <-- no caret
  tokenizer(src) {
    const match = src.match(/^([1-5])\*/); <--- caret
    if (match) {
      return {
        type: 'rating',
        raw: match[0],
        rating: parseInt(match[1]),
      };
    }
  }
};

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@ivanjaros
Comment options

@ivanjaros
Comment options

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