As we all know there is no feature that was implemented by google to highlight syntax on blogger blog while writing a post,but in order to achieve this aim you have to refer to a third party script.Today I will be writing on how to implement syntax highlighter to a blogger blog. Syntax highlighter was created by Alex Gorbatchev.I have also written on other syntax code formatter which are google prettifier and prismjs which also beautify your codes.
How To Install Syntax Highlighter On Blogger
Syntax highlighter comprises of different languages like php,python,ruby,javascript,css,mysql etc but in this tutorial we are going to be install php but before we proceed let make sure we understand the principles behind this tutorial.
The SyntaxHighlighter configuration consists of four parts:
1. The core files
2. The SyntaxHighlighter theme
3. The specific brush(es) needed for the blog
4. The configuration script
1) The core files
The core files consist of the following JavaScript file and style sheet:
2) The SyntaxHighlighter theme
There are a number of themes available for SyntaxHighlighter, the style sheet below is the default theme.
Other themes and How To Implement Theme
To implement other themes,all you just have to do,is to replace shThemeDefault.css with desire theme name.
Django
Output
Eclipse
Output
Emacs
Output
Fade To Grey
Output
Midnight
Output
RDark
Output
3) The specific brush(es) needed for the blog
Depending on the structured language that needs to be highlighted, the corresponding brush needs to be imported. The SyntaxHighlighter site contains a complete list of all available brushes. In this example we will add the brushes for 'PHP' .
Only add the needed brushes as for each page the brushes are retrieved from alexgorbatchev.com (the SyntaxHighlighter site) and this increases your blog page load times!
4) The configuration script
After all needed dependencies have been added we need to enable a specific mode for Blogger and instruct SyntaxHighlighter to highlight all code blocks found on the web page. This is done by adding a JavaScript snippet as shown below.
These are some related topics to these topic:
Installation Procedures
• Login into your blogger dashboard
• Click on Theme follow by Edit HTML
• Press CTRL+F and search for </head>
• Copy and paste the below code before </head>
• Finally Click on Save
Note:If you have follow this steps successfully,you have implemented SyntaxHighlighter to your blogger blog.
SyntaxHighlighter Usage
In order to use SyntaxHighlighter we need to wrap the section to be highlighted with an XML tag called <pre>. This tag has one required parameter called 'brush' which is the same brush that was added in section 3 of the above setup.
For this example we will add a HelloWorld PHP to a <pre> tag with a 'php' brush . Copy the below code and paste it inside a Blogger post.
Make sure all right angle brackets within the <pre> tags are HTML escaped, in other words all < (less than character) must be replaced with “<” (without quotes)!
SyntaxHighlighter Options
In addition to the mandatory 'brush' parameter, the <pre> tag has a number of optional parameters. For example it is possible to highlight one or more lines to focus the reader’s attention by adding the 'highlight' parameter as shown below. Checkout the full list of additional parameters that can be configured.
SyntaxHighlighter is an open source Java Script client side code syntax highlighter.
How To Install Syntax Highlighter On Blogger
Syntax highlighter comprises of different languages like php,python,ruby,javascript,css,mysql etc but in this tutorial we are going to be install php but before we proceed let make sure we understand the principles behind this tutorial.
The SyntaxHighlighter configuration consists of four parts:
1. The core files
2. The SyntaxHighlighter theme
3. The specific brush(es) needed for the blog
4. The configuration script
1) The core files
The core files consist of the following JavaScript file and style sheet:
<script src="http://alexgorbatchev.com/pub/sh/current/scripts/shCore.js" type="text/javascript"></script>
<link href="http://alexgorbatchev.com/pub/sh/current/styles/shCore.css" rel="stylesheet" type="text/css"></link>
2) The SyntaxHighlighter theme
There are a number of themes available for SyntaxHighlighter, the style sheet below is the default theme.
<link href="http://alexgorbatchev.com/pub/sh/current/styles/shThemeDefault.css" rel="stylesheet" type="text/css" />
Other themes and How To Implement Theme
To implement other themes,all you just have to do,is to replace shThemeDefault.css with desire theme name.
Django
<link href="http://alexgorbatchev.com/pub/sh/current/styles/shThemeDjango.css" rel="stylesheet" type="text/css" />
Output
Eclipse
<link href="http://alexgorbatchev.com/pub/sh/current/styles/ shThemeEclipse.css " rel="stylesheet" type="text/css" />
Output
Emacs
<link href="http://alexgorbatchev.com/pub/sh/current/styles/ shThemeEmacs.css " rel="stylesheet" type="text/css" />
Output
Fade To Grey
<link href="http://alexgorbatchev.com/pub/sh/current/styles/ shThemeFadeToGrey.css" rel="stylesheet" type="text/css" />
Output
Midnight
<link href="http://alexgorbatchev.com/pub/sh/current/styles/shThemeMidnight.css" rel="stylesheet" type="text/css" />
Output
RDark
<link href="http://alexgorbatchev.com/pub/sh/current/styles/ shThemeRDark.css " rel="stylesheet" type="text/css" />
Output
3) The specific brush(es) needed for the blog
Depending on the structured language that needs to be highlighted, the corresponding brush needs to be imported. The SyntaxHighlighter site contains a complete list of all available brushes. In this example we will add the brushes for 'PHP' .
<script src="http://alexgorbatchev.com/pub/sh/current/scripts/ shBrushPhp.js " type="text/javascript"></scrip>
Only add the needed brushes as for each page the brushes are retrieved from alexgorbatchev.com (the SyntaxHighlighter site) and this increases your blog page load times!
4) The configuration script
After all needed dependencies have been added we need to enable a specific mode for Blogger and instruct SyntaxHighlighter to highlight all code blocks found on the web page. This is done by adding a JavaScript snippet as shown below.
<script language="javascript" type="text/javascript"> SyntaxHighlighter.config.bloggerMode = true; SyntaxHighlighter.all(); </script>
These are some related topics to these topic:
- How To Implement PrismJs Syntax Highlighting to your Blogger/BlogSpot For Better Formatting
- How to Use Google Prettify Syntax Highlighter With Blogger
Installation Procedures
• Login into your blogger dashboard
• Click on Theme follow by Edit HTML
• Press CTRL+F and search for </head>
• Copy and paste the below code before </head>
<!-- 'SyntaxHighlighter' additions START --> <script src="http://alexgorbatchev.com/pub/sh/current/scripts/shCore.js" type="text/javascript"></script> <link href="http://alexgorbatchev.com/pub/sh/current/styles/shCore.css" rel="stylesheet" type="text/css" /> <link href="http://alexgorbatchev.com/pub/sh/current/styles/shThemeDefault.css" rel="stylesheet" type="text/css" /> <script src="http://alexgorbatchev.com/pub/sh/current/scripts/ shBrushPhp.js " type="text/javascript"></script> <script language="javascript" type="text/javascript"> SyntaxHighlighter.config.bloggerMode = true; SyntaxHighlighter.all(); </script> <!-- 'SyntaxHighlighter' additions END -->
• Finally Click on Save
Note:If you have follow this steps successfully,you have implemented SyntaxHighlighter to your blogger blog.
SyntaxHighlighter Usage
In order to use SyntaxHighlighter we need to wrap the section to be highlighted with an XML tag called <pre>. This tag has one required parameter called 'brush' which is the same brush that was added in section 3 of the above setup.
For this example we will add a HelloWorld PHP to a <pre> tag with a 'php' brush . Copy the below code and paste it inside a Blogger post.
Make sure all right angle brackets within the <pre> tags are HTML escaped, in other words all < (less than character) must be replaced with “<” (without quotes)!
<pre class="brush:php"> <?php $hello = "Hello World"; echo $hello; ?> </pre>
SyntaxHighlighter Options
In addition to the mandatory 'brush' parameter, the <pre> tag has a number of optional parameters. For example it is possible to highlight one or more lines to focus the reader’s attention by adding the 'highlight' parameter as shown below. Checkout the full list of additional parameters that can be configured.
<pre class="brush:php; highlight: [3,4,5]"> <?php $hello = "Hello World"; echo $hello; ?></pre>
SyntaxHighlighter is an open source Java Script client side code syntax highlighter.
Get our updates delivered to your inbox
Howdy! This is my first visit too your blog! We are
ReplyDeletea collection off volunteers and starting a new project inn a communit in the same niche.
Your blog provided us beneficial informatioon tto work on. You
have done a marvellous job!
Hi there I am so delighted I found your website, I really found
ReplyDeleteyou by mistake, while I was browsing on Askjeeve for something else, Nonetheless I am here now and
would just like to say cheers for a incredible post and a all round enjoyable blog (I also love
the theme/design), I don’t have time to look over it all at the moment but I have book-marked it and also added your RSS feeds, so when I have
time I will be back to read more, Please do
keep up the superb jo.
It's going to be end of mine day, except before end I am reading this fantastic piece of writing to improve
ReplyDeletemy know-how.
If you want to improve your know-how only keep visiting this web site and be updated with the hottest
ReplyDeletenews posted here.
This paragraph will help the internet users for creating new weblog or even a weblog from start to end.
ReplyDeleteIf some one desires expert view regarding blogging and
ReplyDeletesite-building afterward i recommend him/her to pay a quick visit this
weblog, Keep up the good work.
Thank you for another informative website. The place else could I
ReplyDeleteget that type of information written in such a perfect way?
I've a challenge that I'm just now working on, and I've
been at the glance out for such info.
When I initially left a comment I appear to have clicked on the -Notify me when new comments are added- checkbox and from now on each time a comment
ReplyDeleteis added I get 4 emails with the exact same comment.
Is there a way you can remove me from that service? Many thanks!
Hi every one, here every person is sharing these kinds of familiarity, thus it's fastidious to read this weblog, and I
ReplyDeleteused to pay a quick visit this weblog every day.
It's actually a nice and useful piece of info.
ReplyDeleteI am happy that you just shared this useful info with us.
Please keep us up to date like this. Thank you for sharing.
I'm very happy to find this website. I want to to thank you for your time for this particularly wonderful read!!
ReplyDeleteI definitely appreciated every part of it and I have you book-marked to check out new information on your web site.
Hello there, just became alert to your blog through Google, and found that it is really informative.
ReplyDeleteI'm going to watch out for brussels. I will be grateful if you continue this in future.
Numerous people will be benefited from your writing. Cheers!
I'm not sure exactly why but this weblog is loading very slow for me.
ReplyDeleteIs anyone else having this problem or is it a problem on my end?
I'll check back later and see if the problem still
exists.
My partner and I stumbled over here different page and thought I might
ReplyDeletecheck things out. I like what I see so now i am following you.
Look forward to checking out your web page for a second
time.
Nice post. I was checking continuously this blog and I'm impressed!
ReplyDeleteExtremely helpful information specially the last part :
) I care for such info much. I was seeking this particular info
for a very long time. Thank you and best of luck.
Greetings! Very helpful advice within this post! It is the
ReplyDeletelittle changes that make the largest changes.
Thanks a lot for sharing!
I am really grateful to the owner of this web page who has shared this
ReplyDeletegreat post at at this place.
It's going to be ending of mine day, however before ending I am reading
ReplyDeletethis great piece of writing to improve my experience.
excellent issues altogether, you simply won a emblem
ReplyDeletenew reader. What could you recommend in regards to your post that you simply made
some days in the past? Any sure?
I know this if off topic but I'm looking into starting my own weblog and
ReplyDeletewas wondering what all is required to get
setup? I'm assuming having a blog like yours would cost a pretty penny?
I'm not very web savvy so I'm not 100% sure. Any tips or advice
would be greatly appreciated. Cheers
Hi I am so grateful I found your web site, I really found you by mistake, while I was looking on Askjeeve for something else, Nonetheless I am here now and would just like to say
ReplyDeletekudos for a tremendous post and a all round thrilling blog
(I also love the theme/design), I don’t have time to read through it all
at the moment but I have saved it and also included your RSS
feeds, so when I have time I will be back to read a lot more, Please do keep up the superb b.
Highly descriptive blog, I enjoyed that a lot.
ReplyDeleteWill there be a part 2?
Appreciate the recommendation. Let me try it out.
ReplyDeleteAhaa, its fastidious conversation on the topic of this paragraph here at this web site, I have read all that,
ReplyDeleteso now me also commenting at this place.