by jchw · 8y ago · 0 comments
One way you could accomplish this is by supporting script tags for this, like wrapping the page in:
<script type="text/markdown">...</script>
...as an optional way to use the library. Browsers won't (shouldn't?) try to render the contents of the script tag before you get to it, so it would act like a typical SPA.example.html:
<script src="mdpage.js"></script><noframes>
# Header
Welcome to my simplest site
- A
- awesome
- list
mdpage.js: document.write("<div id=main></div>");
document.addEventListener("DOMContentLoaded", function() {
var script = document.createElement('script');
script.src = "https://unpkg.com/showdown";
document.head.appendChild(script);
var noframes = document.querySelector('noframes');
script.onload = function() {
var converter = new showdown.Converter({
emoji: true,
underline: true,
})
converter.setFlavor('github')
main.innerHTML = converter.makeHtml(noframes.textContent)
};
});