JavaScript syntax highlighting plugin highlight.js usage "attached highlight.js download" [Original]_javascript Tips

Source: Internet
Author: User
Tags html page php language pack

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:

<! DOCTYPE html>
 
 

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.