@anjuna/docs
Version:
Anjuna Documentation Web Components
43 lines (42 loc) • 1.22 kB
JavaScript
import marked from 'marked';
import prism from 'prismjs';
import 'prismjs/components/prism-sass';
import 'prismjs/components/prism-typescript';
export class Markdown {
componentWillLoad() {
this.renderMarkup();
}
componentWillUpdate() {
this.renderMarkup();
}
renderMarkup() {
this.element.innerHTML = marked(this.precompile(this.data));
prism.highlightAll(false);
}
precompile(markdown) {
if (!markdown) {
return '';
}
let indentStart;
return markdown
.replace(/\>/g, '>')
.split('\n')
.map(line => {
if (line.length > 0 && isNaN(indentStart)) {
indentStart = line.search(/\S|$/);
}
return indentStart ? line.substring(indentStart) : line;
}).join('\n');
}
static get is() { return "ad-markdown"; }
static get properties() { return {
"data": {
"type": String,
"attr": "data"
},
"element": {
"elementRef": true
}
}; }
static get style() { return "/**style-placeholder:ad-markdown:**/"; }
}