Skip to main content

Posting Source Code in Blogger


There are ways to post source code in Blogger.

I had tried Google Code Prettify and SyntaxHighlighter.

I found SyntaxHighlighter, which meets my needs of line numbers, long lines and syntax highlights.

I downloaded the version 4.0.1 from: GitHub.SyntaxHighlighter, and tried to build it.

But, there were many build-issues on Windows (10). There are some solutions on the web, but I didn't try them.


After switching to my Mac mini and installing the node.js 6.11.0 LTS.
(Version 8.1.3 won't work. It produced too many warnings.)

The build was almost smooth, but with just a warning about not supporting the python version 2.7. What I installed on my Mac mini is 3.6.1.

Despite of this warning, I got the files: syntaxhighlighter.js and theme.css with a sample index.html.

Together, they worked fine.

Here are my tests:

SyntaxHightlighter:
def foo():
 for ii in range(10):
   print ii
 if ii > 10:
   print "Error."
 print "This is a very very very very very very very very very very very very very very very very very long line."
 return 0

Coogle Code Prettify:
(updated on 2017/07/12)
After I had added the following style in the head tag.

<style>
pre.prettyprint {
    overflow: auto;
    width: auto;
}
</style>


The scroll bar appears.

def foo():
 for ii in range(10):
   print ii
 if ii > 10:
   print "Error."
 print "This is a very very very very very very very very very very very very very very very very very long line."
 return 0

Comments