mirror of https://github.com/sveltejs/svelte
parent
0d20fb9b8d
commit
1a2af80818
@ -0,0 +1,14 @@
|
||||
import { langs } from '@sveltejs/site-kit/utils/markdown.js';
|
||||
import PrismJS from 'prismjs';
|
||||
import 'prismjs/components/prism-bash';
|
||||
|
||||
export function highlight(source, lang) {
|
||||
const plang = langs[lang] || '';
|
||||
const highlighted = plang ? PrismJS.highlight(
|
||||
source,
|
||||
PrismJS.languages[plang],
|
||||
lang,
|
||||
) : source.replace(/[&<>]/g, c => ({ '&': '&', '<': '<', '>': '>' })[c]);
|
||||
|
||||
return `<pre class='language-${plang}'><code>${highlighted}</code></pre>`;
|
||||
}
|
Loading…
Reference in new issue