Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

147
Views
Change markdown Bullets to html in Javascript

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)

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

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*`))

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!