import { Component, Input, OnInit } from '@angular/core'; import { Http } from '@angular/http'; const hljs = require('highlight.js'); const md = require('markdown-it')({ html: true, linkify: true, typographer: true, highlight: (str: string, lang: string) => { if (lang && hljs.getLanguage(lang)) { try { return '
' +
          hljs.highlight(lang, str, true).value +
          '
'; } catch (__) {} } return '
' + md.utils.escapeHtml(str) + '
'; } }); @Component({ selector: 'include-markdown', template: `
` }) export class IncludeMarkdownComponent implements OnInit { @Input('src') templateUrl: string; templateContent: string; constructor(private http: Http) {} ngOnInit() { this.http.get(this.templateUrl).subscribe((out: any) => { this.templateContent = md.render(out['_body']); }); } }