3 ms·
Why not using marked.js or equivalent, plugging it with a Fetch API instead? example: <html> <head><title>hello</title></head> <body> <main id=root ><
by pvtmert 1y ago
Why not using marked.js or equivalent, plugging it with a Fetch API instead?
example:
<html>
<head><title>hello</title></head>
<body>
<main id=root ></main>
<script src=./marked.min.js async defer ></script>
<script>
async function load() {
let element = document.querySelector("main#root");
await fetch("./index.md")
.then(resp => resp.text())
.then(text => marked(text, { ... }))
.then(html => {
element.innerHTML = html;
});
}
window.onload = load;
</script>
</body>
</html>
since it directly injects the resulting html, you may set "unsafe HTML" option in marked (or markdown.js) and include <title> tags within your markdown document. this will _also_ rewrite the browser title(s)
> edit: formatting
- dtedesco1 1y agoThat’s good if I’m really *only* ever using Markdown. But what about wanting to use React components sometimes? That’s my biggest problem.