I try to use the highlight.js but it didn't work
i work like they say in the website but i don't know what's wrong
<link rel="stylesheet" href="styles/default.css">
<script src="js/highlight.pack.js"></script>
<script>hljs.initHighlightingOnLoad();</script>
<title></title>
</head>
//test the code
<pre><code class="html"><input type="text" name="test" id="test" value=""></code></pre>
<link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/highlight.js/9.7.0/styles/default.min.css">
<script src="//cdnjs.cloudflare.com/ajax/libs/highlight.js/9.7.0/highlight.min.js"></script>
the result in the browser is a normal textbox not the code how to solve this ?
There are many built-in functions in mark. js but we are using two functions for our requirement that is mark() and unmark() function respectively. Here mark() is used to highlight the search text and unmark() is used to remove highlighting the text that is highlighted before.
The <mark> tag defines text that has relevance and is not intended to be used to merely apply highlighter styling. If you wish to style your text to appear highlighted, instead, use a <span> tag with the proper CSS.
Basically, highlight. js lets you easily provide high-quality syntax highlighting without requiring a lot of effort on your part. We're going to show you how to include the code library on any page, and how you can do it in WordPress.
The reason your HTML code is not treated as code by highlight.js
is because the browser parsed the HTML tags. The solution is to replace <
with <
and >
with >
to escape angle brackets. If you included your .js and .css file correctly, make these change will help:
HTML version:
<pre><code class="html"><input type="text" name="test" id="test" value=""></code></pre>
PHP version:
<pre><code class="php"><?php echo"test";?></code></pre>
BTW, no need to use jQuery if you include .js file in HTML <head>
. The script will run after the page loaded.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With