@anjuna/docs
Version:
Anjuna Documentation Web Components
60 lines (59 loc) • 1.9 kB
JavaScript
import marked from 'marked';
import prism from 'prismjs';
import 'prismjs/components/prism-sass';
import 'prismjs/components/prism-typescript';
export class Markdown {
componentDidRender() {
this.renderMarkup();
}
renderMarkup() {
this.element.innerHTML = marked(this.precompile(this.data));
prism.highlightAll(false);
}
precompile(markdown) {
if (!markdown) {
return '';
}
markdown = (markdown.default) ? markdown.default : markdown;
let indentStart;
return markdown
.replace(/\>/g, '>')
.split('\n')
.map(line => {
// find position of 1st non-whitespace character
// to determine the markdown indentation start
if (line.length > 0 && isNaN(indentStart)) {
indentStart = line.search(/\S|$/);
}
// remove whitespaces before indentation start
return indentStart ? line.substring(indentStart) : line;
}).join('\n');
}
static get is() { return "ad-markdown"; }
static get originalStyleUrls() { return {
"$": ["markdown.scss"]
}; }
static get styleUrls() { return {
"$": ["markdown.css"]
}; }
static get properties() { return {
"data": {
"type": "string",
"mutable": false,
"complexType": {
"original": "string",
"resolved": "string",
"references": {}
},
"required": false,
"optional": false,
"docs": {
"tags": [],
"text": "The markdown string to parse"
},
"attribute": "data",
"reflect": false
}
}; }
static get elementRef() { return "element"; }
}