add markdown formatting with code support
This commit is contained in:
18
src/lib/server/markdown.ts
Normal file
18
src/lib/server/markdown.ts
Normal file
@@ -0,0 +1,18 @@
|
||||
import { Marked } from 'marked';
|
||||
import { markedHighlight } from 'marked-highlight';
|
||||
import hljs from 'highlight.js';
|
||||
|
||||
const marked = new Marked(
|
||||
markedHighlight({
|
||||
emptyLangClass: 'hljs',
|
||||
langPrefix: 'hljs language-',
|
||||
highlight(code, lang) {
|
||||
const language = hljs.getLanguage(lang) ? lang : 'plaintext';
|
||||
return hljs.highlight(code, { language }).value;
|
||||
}
|
||||
})
|
||||
);
|
||||
|
||||
export function renderMarkdown(content: string): string {
|
||||
return marked.parse(content, { async: false });
|
||||
}
|
||||
Reference in New Issue
Block a user