generated from markedjs/marked-extension-template
-
Notifications
You must be signed in to change notification settings - Fork 10
Closed
Labels
Description
Hi again.
import { Marked } from 'marked';
import { markedHighlight } from "marked-highlight";
import hljs from 'highlight.js';
const marked = new Marked(
markedHighlight({
langPrefix: 'hljs language-',
highlight(code, lang, info) {
const language = hljs.getLanguage(lang) ? lang : 'plaintext';
return hljs.highlight(code, { language }).value;
}
})
)
console.log(marked.parse(`
\`\`\`
plaintext
<
&
>
\`\`\`
\`\`\`blah
blah lang
<
&
>
\`\`\``));<pre><code>plaintext
<
&
>
</code></pre><pre><code class="hljs language-blah">blah lang
<
&
>
</code></pre>
- Note that if
langis empty, even though it does pass throughhljs.highlight()withplaintextlang, the rendered code has nohljs language-plaintextclass as expected.
Further notes:
highlight(code, lang, info) {
const language = hljs.getLanguage(lang) ? lang : 'blahfakelang';
const out = hljs.highlight(code, { language });
console.log('out:', out);
return out.value;
}leads to uncaught throw:
Could not find the language 'blahfakelang', did you forget to load/include a language module?
/Users/slu/stevenlu.net/node_modules/highlight.js/lib/core.js:2107
throw new Error('Unknown language: "' + languageName + '"');
^
Error: Unknown language: "blahfakelang"
essentially, when lang comes in empty, even though it's converted here to plaintext, it won't take, but when a nonempty lang is specified in the payload, then we override it to be plaintext here and it shows up PROPERLY as plaintext, but we cannot configure an empty lang into plaintext as expected via marked-highlight.
Reactions are currently unavailable