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

optional escape #6

Closed
dvv opened this issue Nov 16, 2011 · 3 comments
Closed

optional escape #6

dvv opened this issue Nov 16, 2011 · 3 comments

Comments

@dvv
Copy link
Contributor

dvv commented Nov 16, 2011

Hi!

If output from marked is fed further to syntax highlighter (say, [https://github.com/andris9/highlight]) the resulting output contains html entities codes instead of symbols.

Wonder if you could make call to escape() optional, or, better, make escape configurable from outside function.

update: marked.escape would fit perfectly, i believe.

TIA,
--Vladimir

@chjj
Copy link
Member

chjj commented Nov 16, 2011

Yeah, I see what you're saying. This sort of delves into another problem. I need to refactor marked completely so it's able to be modified from the outside. I explained it a bit in this pull request. I should really work on it and see what I can do. It looks like people really need this for sanitization, syntax highlighting, and something like GFM.

I'm not sure exposing escape would help too much. If you just had escape do nothing, the code you're trying to highlight wouldn't be escaped, but nothing else would be either. I guess maybe the best thing would be to expose a special escape function/callback to give a chance to highlight code.

@dvv
Copy link
Contributor Author

dvv commented Nov 17, 2011

Well. Currently I'm using visionmedia/jade for rendering. It's capable of escaping per se. Hence, in my patterm, I'd just use identity escape() and let jade do escaping.

@chjj
Copy link
Member

chjj commented Jan 2, 2012

I'm thinking of just checking for an escaped property on each code token. If escaped is present, marked will not escape the code. This would allow for a syntax highlighter to highlight the text contained on the token before feeding it to the parser.

An implementation could look like:

var marked_ = require('marked');

var marked = function(text) {
  var tok = marked_.lexer(text)
    , l = tok.length
    , i = 0
    , t;

  for (; i < l; i++) {
    t = tok[i];
    if (t.type === 'code') {
      t.text = highlight(t.text, t.lang);
      // marked should not escape this
      t.escaped = true;
    }
  }

  text = marked_.parser(tok);

  return text;
};

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