Comments (3)
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.
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.
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)
- Rendering not as expected when using custom elements HOT 1
- Parsed syntax tree cannot be modified (note: will not be implemented) HOT 25
- Invalid regular expression in lower chrome HOT 1
- Multiple list with sublist - <p> tag inserts seems not quite right HOT 1
- marked parse mathematical formula error HOT 14
- Images? ![]() HOT 3
- Escape sequences in links are not unescaped HOT 1
- Lexer handling newlines incorrectly in some cases HOT 1
- Incompatibility with esNext Syntax in marked.js Bundle HOT 6
- Register Walktokens Behavior for extensions with different token structure HOT 4
- Clarify ambiguity around "extensions" HOT 1
- Marked Extensions Versioning HOT 7
- Issues with Parsing Nested Emphasis and Handling Chinese Parentheses HOT 1
- Token with "strong" type was not found HOT 1
- Unexpected token = on static passThroughHooks = new Set() with Next.js HOT 1
- Help with extension HOT 2
- Incorrect handling of valid HTML HOT 2
- Unable to recognize table when the columns count in first row doesn't match the second row HOT 2
- Incorrect handling of multi-line code block HOT 4
- Sanatized HTML HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from marked.