import("https://cdn.jsdelivr.net/npm/marked/marked.min.js"); function include(element, file) { if (file) { const xhttp = new XMLHttpRequest(); xhttp.onreadystatechange = function () { if (this.readyState == 4) { if (this.status == 200) { if ('.md' == file.match(/\.md$/)) { element.innerHTML = marked.parse(this.responseText); } else { element.innerHTML = this.responseText; } } if (this.status == 404) { element.innerHTML = "Page not found."; } } } xhttp.open("GET", file, true); xhttp.send(); } } function parseIncludes() { const elements = document.querySelectorAll('div[include$=".html"]'); elements.forEach((element) => { include(element, element.getAttribute('include')); }); } function page(file) { include(document.getElementById('page'), file); } document.addEventListener('DOMContentLoaded', () => { parseIncludes(); });