Syntaxhighlighter code highlighting plug-in

Source: Internet
Author: User
Syntaxhighlighter is an open-source project on Google Code. It is mainly used to color code on webpages,

It is easy to use and has good results, and supports almost all common languages.

Procedure:

1. Download and decompress syntaxhighlighter (http://download.csdn.net/detail/itmyhome/7757359) current version 3.0.83

Ii. Introduce files

Copy the decompressed scripts and styles folders to the project, and introduceShcore. jsAnd core CSS filesShcore.css

Next, introduce the JS language you want to highlight. For example, to highlight Java, you must introduce shbrushjava. js in the scripts folder.

Finally, the highlighted theme CSS is introduced. The default value isShthemedefault.css

3. the following uses HTML code highlighted as an example.

After introducing JS and CSS files, write the following code:


JavaScript code:

<SCRIPT type = "text/JavaScript"> syntaxhighlighter. defaults ['toolbar'] = false; // remove the question mark icon syntaxhighlighter in the upper right corner. config. tagname = 'pre'; // you can change the default tag for parsing. Syntaxhighlighter. config. bloggermode = true; syntaxhighlighter. config. stripbrs = true; syntaxhighlighter. All (); </SCRIPT>
HTML code:
<PRE class = "Brush: HTML; "> <Table> <tbody> <tr> <TD> Hello </TD> <TD> syntaxhighlighter </TD> </tr> <TD> Code </ TD> <TD> light up </TD> </tr> </tbody> </table> </PRE>
Note: The HTML code is displayed in the <PRE> </PRE> label. By default, syntaxhighlighter automatically searches for the </PRE> label.

The labels can be customized, such as <div> and <p>. You only need to modify the following configuration code:

Syntaxhighlighter. config. tagname = 'div ';

At the same time, choose different format brushes for the root category class name. The preceding example uses HTML. Therefore, the format brush configuration is class = "Brush: HTML ;"


Effect


If the scroll bar appears on the right

Solution:

Find the shcore.css file and find

.syntaxhighlighter table {   width: 100% !important;}
To:

.syntaxhighlighter table {   width: 100% !important;   margin: 1px 0 !important;}


Project demo source code download: http://download.csdn.net/detail/itmyhome/7757359


Reprinted please indicate the source: http://blog.csdn.net/itmyhome1990/article/details/38517737


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.