@@ -2,6 +2,7 @@ import $ from "jquery";
22import logging from "../../core/logging" ;
33import utils from "../../core/utils" ;
44import Base from "../../core/base" ;
5+ import events from "../../core/events" ;
56import inject from "../inject/inject" ;
67
78const log = logging . getLogger ( "pat.markdown" ) ;
@@ -29,11 +30,20 @@ const Markdown = Base.extend({
2930 async render ( text ) {
3031 const marked = ( await import ( "marked" ) ) . marked ;
3132 const DOMPurify = ( await import ( "dompurify" ) ) . default ;
32- await import ( "../syntax-highlight/syntax-highlight" ) . default ;
33+ const SyntaxHighlight = ( await import ( "../syntax-highlight/syntax-highlight" ) ) . default ; // prettier-ignore
3334
3435 const wrapper = document . createElement ( "div" ) ;
3536 const parsed = DOMPurify . sanitize ( marked . parse ( text ) ) ;
3637 wrapper . innerHTML = parsed ;
38+ for ( const item of wrapper . querySelectorAll ( "pre > code" ) ) {
39+ const pre = item . parentElement ;
40+ pre . classList . add ( "pat-syntax-highlight" ) ;
41+ // If the code block language was set in a fenced code block,
42+ // marked has already set the language as a class on the code tag.
43+ // pat-syntax-highlight will understand this.
44+ new SyntaxHighlight ( pre ) ;
45+ await events . await_event ( pre , "init.syntax-highlight.patterns" ) ;
46+ }
3747 return $ ( wrapper ) ;
3848 } ,
3949
0 commit comments