How to use SyntaxHighlighter in Blogger ?


If you are developer and want to share code with proper highlighting & syntax, then there is no proper solution to get it done on blogger. But we can try it out using below steps.

Below HTML code is showing how use Syntax Highlighter in HTML for C++ code.

<!DOCTYPE html>
<html>
<head>
<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/shCore.js' type='text/javascript'></script>
    <script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushCpp.js' type='text/javascript'></script>
<script language='javascript' type='text/javascript'>
        SyntaxHighlighter.all();
    </script>
    <title>SyntaxHighlighter</title>
</head>
<body>
   <pre class="brush: cpp">
#include &lt;iostream>

    int main()
    {
        std::cout<<"hello world!";
        return 0;
    }
</pre>
 </body>
</html>

So create .html file with above code and open it in any browser. (I used Google chrome browser).

Output is :

But same code is not working with blogger, some modification required to do in code to make it work for blogger.


In above code using HTTP protocol, which is not working with blogger theme. You will get error message.

“Editing your theme so it mixes HTTP and HTTPS may affect the security and user experience of your blog when it is viewed over HTTPS”

So we need to use HTTPS protocol to make it work.

So create Google drive as file hosting server. Create folder in Google drive and add .css and .js file which are mention in above code. Change files access as public.


Right click on file -> share… ->Advance -> Who has access ->Public On Web->Done.













 Now again Right click on file -> share…


Copy selected link.


Copy file name e.g. 1JkhJ0kS84rXFcYzRwJDYnGYCGWk7gNS  (String after https://drive.google.com/file/d/)


Replace this link with in above HTML code,
<link href='http://alexgorbatchev.com/pub/sh/current/styles/shCore.css' rel='stylesheet' type='text/css'/>
To
<link href='https://drive.google.com/uc?export=view&id=1SA1i4W1qmaGxuWjCxvbintm5R35yM7E7' rel='stylesheet' type='text/css'/>

Now test html code again with browser. It should show same result.







       


 Now Open Blogger Account. Click on Theme->HTML View

Copy code between <Head>  and <title> tag from HTML file (which we created above) and paste before </head> tag.


Try to save theme. If error observed “Error parsing XML, line 2663, column 56: The reference to entity "id" must end with the ';' delimiter.” Then change & with &amp;  and save again.

       Now create new post. Add below code
<pre class="brush: cpp">
   #include &lt;iostream>

    int main()
    {
        std::cout<<"hello world!";
        return 0;
    }
</pre>
Check preview:








Above steps I used  to add SyntaxHighlighter in Blogger, So you also try it again and add valuable comments.

1 comment:

  1. Casino in the South East - Oyster Casino Reviews
    South East, 사설 사이트 the most luxurious 포커게임하기 casino on the South Shore, is 슬롯 나라 now open for 예스 벳 business. Stay and play at the casino and other casino on 온라인바카라 the South

    ReplyDelete