Cómo - Crear un resaltador de sintaxis
Aprenda a crear y usar un Resaltador de sintaxis.
Resaltador de sintaxis
Los fragmentos de código son más fáciles de leer cuando agrega algo de color:
<!DOCTYPE html>
<html>
<body>
<h1>Testing an HTML Syntax Highlighter</h2>
<p>Hello world!</p>
<a href="https://www.w3schools.com">Back to School</a>
</body>
</html>
<html>
<body>
<h1>Testing an HTML Syntax Highlighter</h2>
<p>Hello world!</p>
<a href="https://www.w3schools.com">Back to School</a>
</body>
</html>
<!DOCTYPE html >
<html >
<body >
<h1 >Prueba de un resaltador de sintaxis HTML </h2 >
<p >¡Hola, mundo! </p >
<a href ="https://www.w3schools.com" >Regreso a clases </a >
</body >
</html >
<html >
<body >
<h1 >Prueba de un resaltador de sintaxis HTML </h2 >
<p >¡Hola, mundo! </p >
<a href ="https://www.w3schools.com" >Regreso a clases </a >
</body >
</html >
Cómo crear un resaltador de sintaxis
Paso 1) Agregar HTML:
Ejemplo
Un <div> que contiene código HTML:
<div id="myDiv">
<!DOCTYPE html><br>
<html><br>
<body><br>
<br>
<h1>Testing an HTML Syntax Highlighter</h2><br>
<p>Hello
world!</p><br>
<a href="https://www.w3schools.com">Back to
School</a><br>
<br>
</body><br>
</html>
</div>
Paso 2) Agregar JavaScript:
Ejemplo
Cree una función llamada "w3CodeColor" y llámela usando el elemento DIV como parámetro:
w3CodeColor(document.getElementById("myDiv"));
function w3CodeColor(elmnt) {
// click "Try it Yourself" to see the JavaScript...
}