JavaScript Marked Play Nice with Highlightjs
TLDR;
You need to use the langPrefix
option to include hljs
class.
Let me start by saying that marked is awesome.
However, if you want to use highlightjs with marked you might run into the issue of your <code>
tags not having a proper background.
That is because, by default it will render the tags as follows:
<code class="lang-php">
highlightjs expects something different:
<code class="hljs lang-php">
You need to use the langPrefix
option to include hljs
class.
marked.setOptions({
langPrefix:'hljs lang-',
highlight: function(code, lang){
if(!lang) return code;
try {
return highlight.highlight(lang, code).value;
} catch(e){
console.error('ERROR', e);
return code;
}
}
});