Closed reflexdemon closed 4 months ago
Here is an example:
<html>
<head>
</head>
<body>
<script src="https://cdn.jsdelivr.net/npm/marked/lib/marked.umd.js"></script>
<script src="https://cdn.jsdelivr.net/npm/marked-highlight/lib/index.umd.js"></script>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/highlightjs/cdn-release@11.9.0/build/styles/default.min.css">
<script src="https://cdn.jsdelivr.net/gh/highlightjs/cdn-release@11.9.0/build/highlight.min.js"></script>
<script>
const { Marked } = window.marked;
const { markedHighlight } = window.markedHighlight;
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;
}
})
);
const div = document.createElement("div");
div.innerHTML = marked.parse(`
\`\`\`javascript
const highlight = "code";
\`\`\`
`);
document.body.append(div);
</script>
</body>
</html>
Does IE 11 10 not support?
No, Microsoft doesn't even support them anymore.
I was trying to add code highlighting to a static html file and this does not seem to be working for me. Can you please add a Browser example like this? https://github.com/bent10/marked-extensions/tree/main/packages/code-format#browser