How do I set up a syntax highlighter on Blogger's new interface? I did try with many options but nothing has worked. Please give any suggestions.
-
12Why close the question? If the question is vague, it can be edited. The answers are good, and helped to solve the problem that is asked. Perhaps move this to webapps.stackexchange.com?– HanxueMar 26, 2014 at 9:28
-
4Absolutely stupid and self-contradictory close reason, very normal for the SO. For syntax highlighting in blogger, use github gist code embedding, the way you post on youtube and embed videos.– ValJul 4, 2014 at 16:00
-
I think its guide available at their own site.. by the way you should look at social content locker for blogger here---stackoverflow.com/questions/27619171/…– craig lerrJan 3, 2015 at 9:22
-
1You can make use of gist.github.com for it, putting your code in blog is not always a great idea if you can't update it ;)– Vinod SrivastavDec 10, 2016 at 10:20
-
@VinodSrivastav Useful idea.– VINOTH ENERGETICApr 28, 2017 at 2:52
3 Answers
1. First, take backup of your blogger template
2. After that open your blogger template (In Edit HTML mode) & copy the all css given in this link before </b:skin>
tag
3. Paste the followig code before </head>
tag
<script src='http://syntaxhighlighter.googlecode.com/svn/trunk/Scripts/shCore.js' type='text/javascript'></script>
<script src='http://syntaxhighlighter.googlecode.com/svn/trunk/Scripts/shBrushCpp.js' type='text/javascript'></script>
<script src='http://syntaxhighlighter.googlecode.com/svn/trunk/Scripts/shBrushCSharp.js' type='text/javascript'></script>
<script src='http://syntaxhighlighter.googlecode.com/svn/trunk/Scripts/shBrushCss.js' type='text/javascript'></script>
<script src='http://syntaxhighlighter.googlecode.com/svn/trunk/Scripts/shBrushDelphi.js' type='text/javascript'></script>
<script src='http://syntaxhighlighter.googlecode.com/svn/trunk/Scripts/shBrushJava.js' type='text/javascript'></script>
<script src='http://syntaxhighlighter.googlecode.com/svn/trunk/Scripts/shBrushJScript.js' type='text/javascript'></script>
<script src='http://syntaxhighlighter.googlecode.com/svn/trunk/Scripts/shBrushPhp.js' type='text/javascript'></script>
<script src='http://syntaxhighlighter.googlecode.com/svn/trunk/Scripts/shBrushPython.js' type='text/javascript'></script>
<script src='http://syntaxhighlighter.googlecode.com/svn/trunk/Scripts/shBrushRuby.js' type='text/javascript'></script>
<script src='http://syntaxhighlighter.googlecode.com/svn/trunk/Scripts/shBrushSql.js' type='text/javascript'></script>
<script src='http://syntaxhighlighter.googlecode.com/svn/trunk/Scripts/shBrushVb.js' type='text/javascript'></script>
<script src='http://syntaxhighlighter.googlecode.com/svn/trunk/Scripts/shBrushXml.js' type='text/javascript'></script>
4. Paste the following code before </body>
tag.
<script language='javascript'>
dp.SyntaxHighlighter.BloggerMode();
dp.SyntaxHighlighter.HighlightAll('code');
</script>
5. Save Blogger Template.
6. Now syntax highlighting is ready to use you can use it with <pre></pre>
tag.
<pre name="code">
...Your html-escaped code goes here...
</pre>
<pre name="code" class="php">
echo "I like PHP";
</pre>
7. You can Escape your code here.
8. Here is list of supported language for <class>
attribute.
-
2
-
2
-
3Talking about step 3, if you put any link (suppose hit this url syntaxhighlighter.googlecode.com/svn/trunk/Scripts/shCore.js in browser) then its given error message 404. That’s an error. The requested URL /svn/trunk/Scripts/shCore.js was not found on this server. That’s all we know. Anyone know about this incident. May 18, 2016 at 11:51
-
3
-
1@Gunaseelan , I have successfully configured using the link oneqonea.blogspot.com.br/2012/04/… as said in stackoverflow.com/a/10374470/3424212 What have changed was to use a CDN (step 5): cdnjs.com/libraries/SyntaxHighlighter Jan 28, 2017 at 21:58
Checkout http://oneqonea.blogspot.com/2012/04/how-do-i-add-syntax-highlighting-to-my.html
It's a really easy "SyntaxHighlighter for Blogger" tutorial with screenshots and everything.
You should be up and running in only a few minutes.
Also, the tutorial is built around the "new interface" you're referring to.
Hope this helps. Happy coding.
-
This link is great. I've used it to incorporate code highlighting in my Software Development Blog. The only thing you should aware of is that the highlighted code will appear only after you publish the post. If you just preview it the code will not be highlighted. This behavior confused me a bit in the beginning. Dec 9, 2012 at 13:00
-
I had issues, and this one worked for me. I just wish it was a guide using the autoloader.– XarcellApr 28, 2013 at 15:08
-
Link only answers are discouraged. It would be great if you can add a gist of it in the answer and redirect it to the link for more details. May 16, 2020 at 15:30
Depending on your template, the SyntaxHighlighter JavaScript code may run before the content has loaded. In that case, changing the code to run after a short timeout should fix the problem. Try this in the <head>
of your template HTML:
<script type="text/javascript"> window.setTimeout(function() { SyntaxHighlighter.config.bloggerMode = true; SyntaxHighlighter.all(); }, 10); </script>
You can add further customisation of defaults before the call to ScriptHighlighter.all()
.
If you want to customise the look and feel of the SyntaxHighlighter code display, add some CSS like this:
.syntaxhighlighter code { font-family: Consolas !important; font-size: 10px !important; }
The !important
is necessary to override the SyntaxHighlighter theme definitions.