Skip to content

Need advice on extending marked with custom markup #57

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
puzrin opened this issue Jun 29, 2012 · 4 comments
Closed

Need advice on extending marked with custom markup #57

puzrin opened this issue Jun 29, 2012 · 4 comments

Comments

@puzrin
Copy link

puzrin commented Jun 29, 2012

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

https://github.com/nodeca/ndoc/blob/master/syntax.md#short-links

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

@madmuffin1
Copy link

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).

@octalmage
Copy link

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!

@elennaro
Copy link

+1 very needed feature!

@puzrin
Copy link
Author

puzrin commented Oct 23, 2014

Closed - not actual anymore. We developped https://github.com/jonschlinkert/remarkable with pluggable syntax.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants