Breaking

Thursday 26 October 2017

How To Implement/Add SyntaxHighlighter To A Blogger Blog

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:

<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:



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 “&lt;” (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



24 comments:

  1. Howdy! This is my first visit too your blog! We are
    a 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!

    ReplyDelete
  2. Hi there I am so delighted I found your website, I really found
    you 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.

    ReplyDelete
  3. It's going to be end of mine day, except before end I am reading this fantastic piece of writing to improve
    my know-how.

    ReplyDelete
  4. If you want to improve your know-how only keep visiting this web site and be updated with the hottest
    news posted here.

    ReplyDelete
  5. This paragraph will help the internet users for creating new weblog or even a weblog from start to end.

    ReplyDelete
  6. If some one desires expert view regarding blogging and
    site-building afterward i recommend him/her to pay a quick visit this
    weblog, Keep up the good work.

    ReplyDelete
  7. Thank you for another informative website. The place else could I
    get 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.

    ReplyDelete
  8. 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
    is added I get 4 emails with the exact same comment.
    Is there a way you can remove me from that service? Many thanks!

    ReplyDelete
  9. Hi every one, here every person is sharing these kinds of familiarity, thus it's fastidious to read this weblog, and I
    used to pay a quick visit this weblog every day.

    ReplyDelete
  10. It's actually a nice and useful piece of info.
    I am happy that you just shared this useful info with us.
    Please keep us up to date like this. Thank you for sharing.

    ReplyDelete
  11. I'm very happy to find this website. I want to to thank you for your time for this particularly wonderful read!!
    I definitely appreciated every part of it and I have you book-marked to check out new information on your web site.

    ReplyDelete
  12. Hello there, just became alert to your blog through Google, and found that it is really informative.
    I'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!

    ReplyDelete
  13. I'm not sure exactly why but this weblog is loading very slow for me.
    Is 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.

    ReplyDelete
  14. My partner and I stumbled over here different page and thought I might
    check 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.

    ReplyDelete
  15. Nice post. I was checking continuously this blog and I'm impressed!
    Extremely 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.

    ReplyDelete
  16. Greetings! Very helpful advice within this post! It is the
    little changes that make the largest changes.
    Thanks a lot for sharing!

    ReplyDelete
  17. I am really grateful to the owner of this web page who has shared this
    great post at at this place.

    ReplyDelete
  18. It's going to be ending of mine day, however before ending I am reading
    this great piece of writing to improve my experience.

    ReplyDelete
  19. excellent issues altogether, you simply won a emblem
    new reader. What could you recommend in regards to your post that you simply made
    some days in the past? Any sure?

    ReplyDelete
  20. I know this if off topic but I'm looking into starting my own weblog and
    was 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

    ReplyDelete
  21. 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
    kudos 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.

    ReplyDelete
  22. Highly descriptive blog, I enjoyed that a lot.
    Will there be a part 2?

    ReplyDelete
  23. Appreciate the recommendation. Let me try it out.

    ReplyDelete
  24. Ahaa, its fastidious conversation on the topic of this paragraph here at this web site, I have read all that,
    so now me also commenting at this place.

    ReplyDelete

Want to get all latest updates from DbencoPlanet.com?

Subscribe to DbencoPlanet to get all the latest updates free!