tablaster.dev/markdown.js
2024-04-22 23:13:01 +05:30

22 lines
No EOL
583 B
JavaScript

function loadMarkdownFile(fileName) {
fetch(`/assets/md/${fileName}`)
.then(response => response.text())
.then(text => {
document.getElementById('markdown').innerHTML = convertMarkdownToHTML(text);
addBlankTargetToLinks();
})
.catch(error => {
console.error('Error loading Markdown file:', error);
});
}
function convertMarkdownToHTML(markdown) {
return marked.parse(markdown);
}
function addBlankTargetToLinks() {
const links = document.querySelectorAll('a');
links.forEach(link => {
link.setAttribute('target', '_blank');
});
}