Syntax Highlighting to Any Project: A Quick Tip

With this post you will be able to implement Syntax Highlighting to your any project, which includes syntax highlighting JavaScript, syntax highlighting vim, XML syntax highlighting, syntax highlighting HTML, python syntax highlighting and miscellaneous.

If you are avid to implement syntax highlighting to your project. Then nothing to worry any more. In this significant tips post I am presenting a syntax highlighter grounded over JavaScript, which is very useful and obvious towards incorporating a functionality of syntax highlighting to any website project. Moreover, it can be also employed on a simple HTML page.

Step 1: Download the Source Code

First of all, your are required to download the source code towards this endeavor. Don’t worry, I am providing the link from where you can download easily without any hurdles.
Download Syntax highlighting code here.

Step 2: Incorporate the src Directory in your Project

Basically, I have renamed this directory to highlighter. So, you shouldn’t delete or modify anything at this point, until you do not forecast it by employing some language specific JavaScript files.

Step 3: Import the requisite files

Throughout your entire HTML file or the page which is authoritative for displaying the view. However, import both the prettify.js and theprettify.css files.

1

2

3

4

5

6

7

8

9

10

11

&lt;!DOCTYPE html&gt;

&lt;html lang="en"&gt;

&lt;head&gt;

&lt;meta charset="utf—8"&gt;

&lt;title&gt;untitled&lt;/title&gt;

&lt;link rel="stylesheet"href="highlighter/prettify.css"/&gt;

&lt;/head&gt;

&lt;body&gt;

&lt;script src="highlighter/prettify.js"&gt;&lt;/script&gt;

&lt;/body&gt;

&lt;/html&gt;

It is the thing to be marked that how we have implanted our script prior to closing the body tag at the bottom of page. It has been always referred as one among the best step, as it enhance the performance too.

Now, we are supposed to perform something. The syntax highlighter will look either for a code or pre element which is accompanied by prettyprint class. So, let’s go ahead to add now.

1

2

3

4

5

6

7

8

&lt;pre class="prettyprint"&gt;

(function()

{

varjsSyntaxHighlighting='rocks';

}

)

();

&lt;/pre&gt;

Step 4: Calling the prettyPrint()Function

Almost we have done it, next we are about to perform the last action of executing the prettyPrint() function. However, you can put this snippet code at the bottom of page.

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

&lt;!DOCTYPE html&gt;

&lt;html lang="en"&gt;

&lt;head&gt;

&lt;meta charset="utf-8"&gt;

&lt;title&gt;untitled&lt;/title&gt;

&lt;link rel="stylesheet"href="highlighter/prettify.css"/&gt;

&lt;/head&gt;

&lt;body&gt;

&lt;pre class="prettyprint"&gt;

(function(){

varjsSyntaxHighlighting='rocks';

})();

&lt;/pre&gt;

&lt;script src="highlighter/prettify.js"&gt;&lt;/script&gt;

&lt;script&gt;prettyPrint();&lt;/script&gt;

&lt;/body&gt;

&lt;/html&gt;

Now, you can see the page in your browser as the image listed below.

So, how affable it was! Now, eventually at bonus step, you would like to know regarding changing the theme of highlighter. Therefore, towards this context you are supposed to modify the stylesheet as it seems to be fit. Also, a bunch of stylesheets are also available in the theme gallery which are absolutely free to employ and are very easy and affable to implement. As for example, let’s assume Desert theme is to be employed.

So, you are required to put a little bit of efforts of copy the CSS snippet code and create a new stylesheet in the project you are working with. Next paste the CSS code into it. Then update the incorporated stylesheet underneath the document’s head section.

Rinniee Ginsburg is a email template developer and writer at EmailChopper. Her technical competency has helped the professionals explore the new techniques in practicing the innovative email development. She has written various articles that accentuate the importance of PSD to Email conversion, smart procedure for responsive email template development & many more. All her writeups have become a source for many professionals and business players to grab the valuable information.

Explore the trendiest & the most captivating techniques of the web world. This is a grand platform where anyone can learn and share the informative concept & useful tips that revolve around the web development.