@@ -60,31 +60,39 @@ export class MarkdownDirective implements OnChanges, OnDestroy {
6060 this . el . innerHTML = value ;
6161 return ;
6262 } else {
63- const MarkdownIt = await this . markdownIt ;
64- const md = new MarkdownIt ( {
65- html : true ,
66- linkify : true ,
67- } ) ;
68-
69- const html = this . sanitizer . sanitize ( SecurityContext . HTML , md . render ( value ) ) ;
70- this . el . innerHTML = html ;
71-
7263 if ( environment . markdown . mathjax ) {
73- this . renderMathjax ( ) ;
64+ this . renderMathjaxThenMarkdown ( value ) ;
65+ } else {
66+ this . renderMarkdown ( value ) ;
7467 }
7568 }
7669 }
7770
78- private renderMathjax ( ) {
71+ private renderMathjaxThenMarkdown ( value : string ) {
72+ const sanitized = this . sanitizer . sanitize ( SecurityContext . HTML , value ) ;
73+ this . el . innerHTML = sanitized ;
7974 this . mathService . ready ( ) . pipe (
8075 filter ( ( ready ) => ready ) ,
8176 take ( 1 ) ,
8277 takeUntil ( this . alive$ )
8378 ) . subscribe ( ( ) => {
84- this . mathService . render ( this . el ) ;
79+ this . mathService . render ( this . el ) ?. then ( _ => {
80+ this . renderMarkdown ( this . el . innerHTML , true ) ;
81+ } ) ;
8582 } ) ;
8683 }
8784
85+ private async renderMarkdown ( value : string , alreadySanitized = false ) {
86+ const MarkdownIt = await this . markdownIt ;
87+ const md = new MarkdownIt ( {
88+ html : true ,
89+ linkify : true ,
90+ } ) ;
91+
92+ const html = alreadySanitized ? md . render ( value ) : this . sanitizer . sanitize ( SecurityContext . HTML , md . render ( value ) ) ;
93+ this . el . innerHTML = html ;
94+ }
95+
8896 ngOnDestroy ( ) {
8997 this . alive$ . next ( false ) ;
9098 }
0 commit comments