File tree Expand file tree Collapse file tree 1 file changed +12
-8
lines changed
apps/codever-ui/src/app/shared/pipe Expand file tree Collapse file tree 1 file changed +12
-8
lines changed Original file line number Diff line number Diff line change @@ -4,14 +4,18 @@ import * as DOMPurify from 'dompurify';
44import { marked } from 'marked' ;
55import hljs from 'highlight.js' ;
66
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- } ) ;
7+ // Custom renderer to apply highlight.js syntax highlighting to fenced code blocks
8+ // and add the 'hljs' CSS class so the github-dark theme (included in angular.json) is applied
9+ const renderer = new marked . Renderer ( ) ;
10+ renderer . code = function ( code : string , language : string ) {
11+ const lang = language && hljs . getLanguage ( language ) ? language : null ;
12+ const highlighted = lang
13+ ? hljs . highlight ( code , { language : lang } ) . value
14+ : hljs . highlightAuto ( code ) . value ;
15+ return `<pre><code class="hljs${ lang ? ' language-' + lang : '' } ">${ highlighted } </code></pre>` ;
16+ } ;
17+
18+ marked . setOptions ( { renderer } ) ;
1519
1620@Pipe ( { name : 'md2html' } )
1721export class Markdown2HtmlPipe implements PipeTransform {
You can’t perform that action at this time.
0 commit comments