-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
How to use highlight.js outside the browser? #578
Comments
There is documentation in marked for this. The example only uses auto highlighting when it is possible to specify a language like the Pygments example. var fs = require('fs');
var hljs = require('highlight.js');
var marked = require('marked');
var markdownString = fs.readFileSync('./README.md');
marked.setOptions({
highlight: function(code, lang) {
return hljs.highlight(lang, code).value;
}
});
var output = marked(markdownString); |
Nice. Thanks, @sourrust |
Give a compatible version: marked.setOptions({
highlight: function(code, lang) {
if (typeof lang === 'undefined') {
return hljs.highlightAuto(code).value;
} else if (lang === 'nohighlight') {
return code;
} else {
return hljs.highlight(lang, code).value;
}
}
}); |
Hello,
Node version:
Source file:
|
@stla we had some trouble running highlight.js at scale, and created https://github.com/npm/marky-markdown which uses https://github.com/atom/highlights to do syntax highlighting. |
Thank you. The conversion works with |
Are you converting in the browser, or in node? |
First of all, do I understand it right that the bug in question has nothing to do with highlight.js? Looks like it's something in marked. Also, @zeke, could you please elaborate on this:
What scale, what was the problem (slow? bugs?) Thanks! |
In late 2014, we (npm, Inc) tried to use highlight.js to process the READMEs of all npm packages (about 90,000 of them at the time). Many of these markdown files contained code snippets that would cause highlight.js to leak memory and eventual crash the node process. We spent a good amount of time trying to debug it, but eventually moved to |
Huh… Were you able to get any insights about the possible sort of memory leaks? One should be really unlucky to get that in a managed language, I can't think of anything unusual we might do in our code to cause memory leaks. |
I tried in node and using the executable. I get output like:
There's no css styles except |
@stla what does your source input look like? |
This is a Haskell script. Using pandoc, the conversion is perfect.
@stla what does your source input look like?— |
I'm considering pre-highlighting code on the server-side to avoid making users download the highlight.js library, but I'm not exactly sure how to do it.
Say I have a README file in Markdown, and I use
marked
to parse it into HTML:Now I have this HTML:
How would I use highlight.js to apply syntax highlighting markup to this HTML string? Please forgive me if I missed the documentation somewhere that explains this. :)
The text was updated successfully, but these errors were encountered: