At the moment I have a function
export function markdownToHtml(mdText) {
const toHTML = mdText
.replace(/^### (.*$)/gim, "<h3>$1</h3>") // h3 tag
.replace(/^## (.*$)/gim, "<h2>$1</h2>") // h2 tag
.replace(/^# (.*$)/gim, "<h1>$1</h1>") // h1 tag
.replace(/\*\*(.*)\*\*/gim, "<b>$1</b>") // bold text
.replace(/\*(.*)\*/gim, "<i>$1</i>") // italic text
.replace(/\[(.*?)\]\((.*?)\)/gim, "<a href='$2'>$1</a>") // link
return toHTML.trim() // using trim method to remove whitespace
}
where I am parsing some of the Markdown styles to HTML but I'm missing the regex to parse bullet points.
any Idea? (not using a dependecy is better)
Something like this?
It does not wrap in UL
function markdownToHtml(mdText) {
const toHTML = mdText.split("\n").map(text => text
.trim() // using trim method to remove whitespace
.replace(/^### (.*$)/i, "<h3>$1</h3>") // h3 tag
.replace(/^## (.*$)/i, "<h2>$1</h2>") // h2 tag
.replace(/^# (.*$)/i, "<h1>$1</h1>") // h1 tag
.replace(/^\* (.*$)/i, "<li>$1</li>") // <li> tag
.replace(/\*\*(.*)\*\*/i, "<b>$1</b>") // bold text
.replace(/\*(.*)\*/i, "<i>$1</i>") // italic text
.replace(/\*(.*)\*/i, "<i>$1</i>") // italic text
.replace(/\[(.*?)\]\((.*?)\)/i, "<a href='$2'>$1</a>")) // link
return toHTML.join("\n")
}
console.log(markdownToHtml(`### Title\n* *Bold bullet*`))