Coder Social home page Coder Social logo

optional escape about marked HOT 3 CLOSED

markedjs avatar markedjs commented on May 23, 2024
optional escape

from marked.

Comments (3)

chjj avatar chjj commented on May 23, 2024

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.

from marked.

dvv avatar dvv commented on May 23, 2024

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.

from marked.

chjj avatar chjj commented on May 23, 2024

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;
};

from marked.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.