summaryrefslogtreecommitdiff
path: root/markdown.js
blob: 4b9521f75a599d84e6041e6a431b557038a97ec4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
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 => {
    if (!link.getAttribute('href').startsWith('http') && !link.getAttribute('href').startsWith('https')) {
      return;
    }
    link.setAttribute('target', '_blank');
  });
}