Skip to content
\n

plus some html wrappers.

\n

The extension must also work with child tokens so quote can embed another quote and so on.

\n

The base is simple:

\n
const quote = {\n  name: 'quote',\n  level: 'block',\n  start(src) {\n    const m = src.match(/^\\[quote\\](\\S*?)\\[\\/quote\\]/) <-- this works for inline types but does it for blocks as well?\n    return m ? m.index : null\n  },\n  tokenizer(src, tokens) {\n    const rule = /^\\[quote\\](\\S*?)\\[\\/quote\\]/;\n    const match = rule.exec(src);\n    if (match) {\n      return {\n        type: \"quote\",\n        raw: match[0],\n        user_id: \"\", @todo \n        user_name: \"\", @todo \n        message: \"\", @todo \n        timestamp: 0, @todo \n      }\n    }\n  },\n  renderer(token) {\n    return '<script rel=\"quote\" type=\"application/json\">' + JSON.stringify({uid: token.user_id, name: token.user_name, timestamp: token.timestamp, message: token.message}) + '</script>'\n  }\n};\n
\n

I am using script render because in case the renderer is not configured to recognize the extension, the html sanitizer will simply remove it altogether from the final result.

\n

I think I can figure out the children rendering. I have one component that does it(this.lexer.inline(token.text, token.tokens); so it should be the same thing. Which leaves the pattern matching to find out the user id, name, timestamp. Which are optional.

\n

I would guess I should do sub-pattern matching for the [quote] and simply look for the individual attributes inside? Though am not sure how to handle space in the name, for example. Maybe using quotes would make more sense, like [quote name=\"John Doe\"]?

\n

But am also not sure how properly render the children in case of quote containing another quote so the regex works as it it supposed to...

\n

Anyone done block extension like this and can help out?

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

...ah, it's the next day, i have a clear head, i think i will just add a new tag, like [user=123]john doe[/user] and prepend the quote with it, rather than try to make the original idea work. even here on github, it does not use anything more than a markdown blockquote. the main idea was merely to be able to notify the user about being mentioned, so this will do just that without having to alter anything related to quotes themselves.

","upvoteCount":0,"url":"https://github.com/markedjs/marked/discussions/3399#discussioncomment-10302894"}}}
Discussion options

You must be logged in to vote

...ah, it's the next day, i have a clear head, i think i will just add a new tag, like [user=123]john doe[/user] and prepend the quote with it, rather than try to make the original idea work. even here on github, it does not use anything more than a markdown blockquote. the main idea was merely to be able to notify the user about being mentioned, so this will do just that without having to alter anything related to quotes themselves.

Replies: 1 comment 3 replies

Comment options

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

@UziTech
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