Add d-code and d-math componenents. Needs styling.

This commit is contained in:
Ludwig Schubert
2017-07-21 17:48:39 -07:00
parent 031e3b52b9
commit 4f3ddce184
11 changed files with 10591 additions and 456 deletions
+36
View File
@@ -0,0 +1,36 @@
import katex from "katex";
export const html = `
<style>
dt-math[block] {
display: block;
}
</style>
`;
export class Math extends HTMLElement {
constructor() {
super();
const options = {childList: true};
let observer = new MutationObserver( (mutations) => {
observer.disconnect();
this.renderComponent();
observer.observe(this, options);
})
// try a first render
this.renderComponent();
// listen for changes
observer.observe(this, options);
}
renderComponent() {
const displayMode = this.hasAttribute("block");
const options = { displayMode: displayMode };
const renderedMath = katex.renderToString(this.textContent, options);
this.innerHTML = html + renderedMath
}
}
customElements.define("d-math", Math);