Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

142
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda