1
0
mirror of https://github.com/avinal/avinal.github.io.git synced 2026-07-04 07:40:09 +05:30

add new elm-land website

Signed-off-by: Avinal Kumar <avinal.xlvii@gmail.com>
This commit is contained in:
2023-01-02 12:45:21 +05:30
parent 0097117553
commit 239c67da1c
19 changed files with 2389 additions and 11 deletions
+58
View File
@@ -0,0 +1,58 @@
import "./prism.js";
customElements.define(
"rendered-md",
class extends HTMLElement {
constructor() {
super();
}
connectedCallback() {
this.runMarked();
}
attributeChangedCallback(name, oldValue, newValue) {
this.runMarked();
}
runMarked() {
const renderer = new marked.Renderer();
const data = this.getAttribute("markdowndata");
renderer.heading = (text, level) => {
if (level === 1) {
return `<header>
<h1>
${text}</h1>
</header>`;
}
const escapedText = text
.trim()
.toLowerCase()
.replace(/[^\w]+/g, "-");
return `<h${level} id="${escapedText}">
${text}
<a title="Permalink to ${text}" href="#${escapedText}">
#
</a>
</h${level}>`;
};
marked.setOptions({
renderer: renderer,
highlight: function (code, lang) {
const grammer = Prism.languages[lang];
if (!grammer) {
console.warn(`Unable to find prism highlight for '${lang}'`);
return;
}
console.info("Found", lang);
return Prism.highlight(code, grammer, lang);
},
});
this.innerHTML = marked.parse(data);
console.log("Markdown rendering complete!");
}
static get observedAttributes() {
return ["markdowndata"];
}
}
);
File diff suppressed because one or more lines are too long