This example describes the JavaScript syntax Gao Lianku highlight.js usage. Share to everyone for your reference, specific as follows:
Highlight.js is a JavaScript based grammar Gao Lianku, currently supports 125 programming languages, there are 63 alternative styles, and can do automatic language recognition, and the current mainstream JS framework can be compatible, can be mixed use.
This Gao Lianku can be used in the blog system, its use method and its simple, almost no need for any learning costs, the following describes the use of highlight.js.
1. Obtain the Highlight.js library, the user can obtain from the official website:
Address: https://highlightjs.org/download/
Highlight.js Library Support Online customization, according to the default selection click Download can:
Or click here to download the site .
2. After the download decompression, the file structure is as follows:
Styles directory for all CSS styles, highlight.pack.js as a library file.
3. Introduce Default.css and highlight.pack.js to the HTML page, the following code:
<link rel= "stylesheet" href= "Highlight/styles/default.css" >
<script src= "Highlight/highlight.pack.js" "></script>
4. Loading the Highlight.js library, the code is as follows:
<script>
hljs.inithighlightingonload ();
</script>
5. Add the code to be highlighted in the
<pre>
<code class= "php" >
<?php
//using Substr_replace function for string insertion demo
$str = "Welcome to Yun-Habitat community" ;
Echo Substr_replace ($str, "\" php great god \ "", 4,0);
Output: Welcome to the "Great God of php" to cloud Habitat Community
?>
</code>
</pre>
The class attribute specifies the language category, which is specified as the PHP language in the code above.
The complete code looks like this:
The preview effect is as follows:
More readers interested in JavaScript-related content can view the site topics: "JavaScript data structure and algorithm skills summary", "JavaScript switching effects and techniques summary", "JavaScript Search Algorithm Skills summary", " JavaScript animation effects and tips Summary, "JavaScript Error and debugging skills Summary", "JavaScript traversal algorithm and Skills summary" and "JavaScript Mathematical calculation Usage Summary"
I hope this article will help you with JavaScript programming.