You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
svelte/site/src/utils/highlight.js

17 lines
537 B

import { langs } from '@sveltejs/site-kit/utils/markdown.js';
import PrismJS from 'prismjs';
import 'prismjs/components/prism-bash.js';
import 'prismjs/components/prism-diff.js';
import 'prism-svelte';
export function highlight(source, lang) {
const plang = langs[lang] || '';
const highlighted = plang ? PrismJS.highlight(
source,
PrismJS.languages[plang],
lang,
) : source.replace(/[&<>]/g, c => ({ '&': '&amp;', '<': '&lt;', '>': '&gt;' })[c]);
return `<pre class='language-${plang}'><code>${highlighted}</code></pre>`;
}