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

174
Vistas
How to make a syntax highlighter that highlights symbols

I wanted to make a syntax highlighter that highlights symbols. Look at the example:

function hello(){
  return "hello";
}

I want to highlight all the symbols:

{([</!&|\>])};.,:=+*-@$~_^?%'"

And I made a little one that highlighted strings. When I wanted to make one that highlights symbols I got confused. Now I want to know What topics should I learn to make it? Any example, github repo, tutorial, topic or ...? EDIT: I found the way to do that but I still have problem. My code is the following:

function syntaxue(){
  var codes = document.getElementsByClassName("syntaxue");
  for (var i=0; i < codes.length; i++){
    var data = codes[i].innerHTML;
    data = data.replace(/([^\w\s])/g, '<span class="sym">$1</span>');
    data = data.replace(/([\d])/g, '<span class="num">$1</span>');
    codes[i].innerHTML = data;
  }
}

When I want to highlight strings, the code becomes sth else.(Sorry I'm not English) And I was testing HTML markup I saw this:

&lt;html&gt;

Instead of this:

<html>

And the &; symbols were highlighted not their results. Can anyone help me?

about 4 years ago · Juan Pablo Isaza
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