JSFiddle - React, Tailwind, and code Playground
by BramVanroy
HTML
<div id="html">
<code><div>This div is HTML</div></code>
<code><!-- This is a HTML Comment --></code>
<code><pre>
<!DOCTYPE html><br><html><br><head><br><title>Title of the document</title><br></head>
<body><br><!-- The content of the document... --><br></body><br>
</html>
</pre></code>
</div>
<div id="css">
<code><pre>#thisiscss {<br> margin: 0;<br> padding: 0;<br>}</pre></code>
<code><pre>.thisismorecss {<br> border: 1px solid;<br> color: white;<br>}</pre></code>
<code><pre>p {<br> color: red;<br> /* This is a single-line comment */<br> text-align: center;<br>}<br><br>/* This is<br>a multi-line<br>comment */<br><br>*, *:before, *:after {margin: 0;}</pre></code>
</div>
<div id="js">
<code>document.getElementById("demo").innerHTML = "Hello JavaScript";</code>
<code><pre>var p1;<br>var p2;<br>function myFunction(p1, p2) {<br> return p1 * p2; // The function returns the product of p1 and p2<br>}</pre></code
</div>
CSS
code {
margin: 20px 0;
display: block;
}
div {
margin: 20px auto 0;
border-bottom: 6px #333 solid;
padding: 20px;
}
span {
font-weight: bold;
color: blue;
}
JavaScript
$("code").each(function () {
code = $(this).text();
// Tests against opening html tags, doctype & comments
if (code.match(/(^(<([^>]+)(\s[^>])*>(.|\r|\n)*<\/\3>))|(^<!((doctype html[^>]*)|(--.*?--))>)/i)) {
$(this).after("<span>This is HTML</span>");
} else if (code.match(/((#|\.)?[^{\/]+{(.|\r|\n)*?})|(^\/\*(.|\r|\n)*?\*\/)/)) {
$(this).after("<span>This is CSS</span>");
} else {
$(this).after("<span>This is JS</span>");
}
});