import { Directive , ElementRef , Renderer2 } from '@angular/core' ; import * as marked from 'marked' ; /**
 * Convert the contents of the decorated element from Markdown into HTML.
 *
 * Usage:
 * <div mMarkdown>
 * # I am a header!
 *
 * I am a paragraph!
 * </div>
 * ```
 */ @ Directive ( { selector : '[mMarkdown]' , } ) export class MarkedDirective { constructor ( private el , private renderer ) { setTimeout ( ( ) => { this . parse ( ) ; } ) ; } parse ( ) { const markText = this . el . nativeElement . innerHTML ; if ( markText && markText . length > 0 ) { const markdownHtml = marked ( markText ) ; this . renderer . setProperty ( this . el . nativeElement , 'innerHTML' , markdownHtml ) ; } } }