Skip to content

Commit e62ef47

Browse files
committed
feat(notes): highlight code in notes
1 parent f25a6df commit e62ef47

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

apps/codever-ui/src/app/shared/pipe/markdown2html.pipe.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,16 @@ import { Pipe, PipeTransform } from '@angular/core';
22
import * as DOMPurify from 'dompurify';
33

44
import { marked } from 'marked';
5+
import hljs from 'highlight.js';
6+
7+
marked.setOptions({
8+
highlight: function (code: string, lang: string) {
9+
if (lang && hljs.getLanguage(lang)) {
10+
return hljs.highlight(code, { language: lang }).value;
11+
}
12+
return hljs.highlightAuto(code).value;
13+
},
14+
});
515

616
@Pipe({ name: 'md2html' })
717
export class Markdown2HtmlPipe implements PipeTransform {

0 commit comments

Comments
 (0)