Skip to content


Subversion checkout URL

You can clone with
Download ZIP


Need advice on extending marked with custom markup #57

puzrin opened this Issue · 4 comments

4 participants


We need to extend marked with [[reference]] syntax, that woud work in the same way, like highlight (via external function call)

Could you explain, how to monkeypatch marked, to add this inline tag?


I am also looking into extending marked.

I am trying to implement a new inline rule, which is supposed to translate anything like
[A]something into <span class="chord">A</span>something and came up with this:

marked.InlineLexer.rules.chord = /^\[([^\n\]]+)\]/;
marked.Renderer.prototype.chord = function(text) {
  return '<span class="chord">' + text + '</span>';

So I am injecting a new rule into the lexer and prototyped the replace function I am looking for. Unfortunately, this seems not to be enough. What am I missing? Would be grateful for any hints.

EDIT: I haven't thoroughly looked into the code when I posted this, I suspected the rules to act like a chain, but it seems they don't. In order to make this work, some lines need to be added to the InlineLexer.prototype.output function, which is not actually possible without modifying the code. Though I might look into this more later, I want to just note down one finding: the function InlineLexer contains a line this.rules = inline.normal;. I suggest changing it to this.rules = InlineLexer.rules || inline.normal;, so changes made trough the exposed rules are accessible from within marked (as mentioned above, this does not help much though).


In my app I ended up pre-parsing the markdown using regex to add custom syntax, but I'd love to have this built in!


+1 very needed feature!


Closed - not actual anymore. We developped with pluggable syntax.

@puzrin puzrin closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.