tablaster.dev/markdown.js

22 lines
583 B
JavaScript
Raw Normal View History

2024-04-21 13:37:26 +02:00
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');
});
}