The highlight.js API for registering only the languages you need is:
import hljs from 'highlight.js/lib/core';
import javascript from 'highlight.js/lib/languages/javascript';
hljs.registerLanguage('javascript', javascript);
This makes it friendly for importing only the language you need in a syntax highlighting component.
For example (Svelte):
<script>
import hljs from 'highlight.js/lib/core';
export let language;
export let code;
const highlighterPromise = (async function () {
const highlighter = await import(`./languages/${language}.js`);
hljs.registerLanguage(language, highlighter);
return hljs.highlight;
})();
</script>
{#await highlighterPromise then highlight}
<code>{highlight(code)}</code>
{/await}
Please also export src/svelte.js:#hljsDefineSvelte as part of the highlightjs-svelte public API. This matches the highlight.js API for other languages to allow the above pattern.
The highlight.js API for registering only the languages you need is:
This makes it friendly for importing only the language you need in a syntax highlighting component.
For example (Svelte):
Please also export src/svelte.js:#hljsDefineSvelte as part of the
highlightjs-svelte
public API. This matches the highlight.js API for other languages to allow the above pattern.