Skip to content
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

Can't run Multiple Lexers #215

Closed
martindale opened this issue Aug 2, 2013 · 1 comment
Closed

Can't run Multiple Lexers #215

martindale opened this issue Aug 2, 2013 · 1 comment

Comments

@martindale
Copy link

This is a (non-functional) example of what I was attempting:

var lexers = {
    chat: new marked.InlineLexer([], {sanitize: true, smartypants:true, gfm:true})
  , content: new marked.Lexer({sanitize: true, smartypants:true, gfm:true})
};
// disable images, but allow links
lexers.chat.rules.link = /^\[((?:\[[^\]]*\]|[^\]]|\](?=[^\[]*\]))*)\]\(\s*<?([^\s]*?)>?(?:\s+['"]([\s\S]*?)['"])?\s*\)/;

Unfortunately, the Lexer and InlineLexer classes don't behave the same way, so...

var lexers = {
    chat: new marked.InlineLexer([], {sanitize: true, smartypants:true, gfm:true})
  , content: marked
};
// disable images, but allow links
lexers.chat.rules.link = /^\[((?:\[[^\]]*\]|[^\]]|\](?=[^\[]*\]))*)\]\(\s*<?([^\s]*?)>?(?:\s+['"]([\s\S]*?)['"])?\s*\)/;

Should work, by exposing lexer.content( ) as a direct mapping to the non-inline Marked parser. Unfortunately, it doesn't -- the editing of the InlineLexer via changing the rules also impacts the second marked function.

As a workaround, I attempted:

var otherMarked = require('marked');
var lexers = {
    chat: new eval(marked.InlineLexer)([], {sanitize: true, smartypants:true, gfm:true})
  , content: otherMarked
};
// disable images, but allow links
lexers.chat.rules.link = /^\[((?:\[[^\]]*\]|[^\]]|\](?=[^\[]*\]))*)\]\(\s*<?([^\s]*?)>?(?:\s+['"]([\s\S]*?)['"])?\s*\)/;

...to no avail. Perhaps we should unify the lexer structures and/or standardize how they are exposed?

@joshbruce
Copy link
Member

Closing as stale. Please see #956 and please re-submit if you are still using and marked and the defect is still present.

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

2 participants