-
-
Save jpokan/e23e5606921b4a5aa98fd2dc2dd0e116 to your computer and use it in GitHub Desktop.
Use marked and prism.js to parse markdown and add syntax highlighting in Node.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Versions: marked v0.6.2, prismjs v1.15.0 | |
let marked = require('marked'); | |
let prism = require('prismjs'); | |
let loadLanguages = require('prismjs/components/'); | |
loadLanguages(['javascript', 'jsx', 'css', 'markup', 'bash', 'json']); | |
marked.setOptions({ | |
highlight: function(code, lang) { | |
if (prism.languages[lang]) { | |
return prism.highlight(code, prism.languages[lang], lang); | |
} else { | |
return code; | |
} | |
} | |
}); | |
let someMarkdown = "```javascript\nlet x = 2;```"; | |
let html = marked.parse(someMarkdown) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment