Comments (5)
I don't know if I'd want to implement this. Any other highlighter you can use from inside node is going to be synchronous. It would really be a lot of changes for one specific case.
You could probably hack it into the exposed function easily enough: (warning, untested)
var marked = function(src, func) {
return func
? marked.async(src, func)
: parse(block.lexer(src));
};
marked.async = function(src, func) {
var src = block.lexer(src)
, highlight = options.highlight
, pending = 0
, l = src.length
, i = 0;
if (!highlight || highlight.length < 3) {
return func(null, parse(src));
}
for (; i < l; i++) {
(function(tok) {
if (tok.type !== 'code') return;
pending++;
highlight(tok.text, tok.lang, function(err, code) {
if (code == null || code === tok.text) {
return --pending || done();
}
tok.text = code;
tok.escaped = true;
--pending || done();
});
})(src[i]);
}
if (!pending) return done();
function done() {
delete options.highlight;
func(null, parse(src));
options.highlight = highlight;
}
};
// usage
marked.setOptions({
gfm: true,
highlight: pygments
});
marked(text, function(err, text) {
console.log(text);
});
from marked.
I had the same issue, and your code above appears to work.
I went ahead and got them working together, in case anyone else wants to see, the code is here and test sample usage here
from marked.
@chjj Would you accept a pull request if I added implement the async API?
from marked.
@fortes, it depends on how you implement it. I might add it in the way mentioned above, but an entire refactor of the parser is not appealing to me, and I worry about any overhead that the async refactor might add.
from marked.
@chjj I'll take a crack at it when I get some spare cycles, and you can see what you think. I'm not interested in maintaining a fork, so if it's not something that will go into master, I'll come up with another solution for fortes/enfield.
Great work on marked, btw. Easily the best of the node.js markdown parsers.
from marked.
Related Issues (20)
- Private identifiers are only available when targeting ECMAScript 2015 and higher. HOT 1
- **xxx: * * No<strong>tags added HOT 1
- Using blobs with walkTokens results in stripped img src HOT 4
- Won't load on safari HOT 2
- marked.parseInline() returns string | Promise<string> even when { async: false } HOT 4
- Code block inside code block HOT 1
- id disapear after markdown parsing HOT 1
- use <br> with CRLF line endings wrong output HOT 14
- Handle [!NOTE] HOT 1
- v11.0.0. yields "Uncaught Error: renderer 'options' does not exist" in code that worked in versions up to v10.0.0 HOT 3
- Task List, Unordered List and Blockquote Bugs, along with Suggestions for Improvement HOT 2
- Proposal: mark-down html element HOT 1
- Marked treats tabs and spaces differently in lists
- Error: renderer 'options' does not exist HOT 1
- MiniProgramError SyntaxError: Invalid regular expression: /[\p{L}\p{N}]/: Invalid property name in character class HOT 1
- 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
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.