ZoeysBits/js/articleload.js
2023-12-21 01:01:16 +01:00

23 lines
950 B
JavaScript

// Function to convert Markdown to HTML
function convertMarkdownToHTML(markdownContent) {
// Simple Markdown to HTML conversion
// This is a basic example and may not cover all Markdown features
// You may need to enhance this function based on your requirements
return markdownContent
.replace(/\*\*(.*?)\*\*/g, '<strong>$1</strong>') // Bold
.replace(/\*(.*?)\*/g, '<em>$1</em>'); // Italics
}
// Function to fetch and display an article
function displayArticle(articlePath) {
fetch(articlePath)
.then(response => response.text())
.then(markdownContent => {
const htmlContent = convertMarkdownToHTML(markdownContent);
document.getElementById('article-container').innerHTML = htmlContent;
})
.catch(error => console.error('Error fetching article:', error));
}
// Call the function with the path to your Markdown file
displayArticle('/md/rants/test.md');