Testing Online Code Syntax Highlighters for Blogs (2): highlight.js

Now I know the reason for failing to make highlight.js work on my blog yesterday. It is because of Blogger's dynamic view, which is the real thing that I'm going to give up using forever. For details, refer to my newer post.
(updated on 8/1/14 09:45 GMT)

Thanks to Chris, I know more ways of embedding source code lists now.
Confucius said that we need to practice what we've learnt. So this is my sample usage of highlight.js.
In my previous post titled Fast Compilation and Execution of Source Code, I included the following sample makefile:
hello : hello.c
    gcc -o hello hello.c
    rm -f hello
Note: See the note of making a makefile in the previous blog post. In order to include this list, I used Alex Gorbatchev's SyntaxHighlighter to do this.
<pre class="brush: text;">hello : hello.c
    gcc -o hello hello.c
    rm -f hello
This template looks pretty, but there's some inadequacies for me:
  1. Makefile (and other popular languages as well) support
  2. Multiple language syntax detection: For example, in the second source code list, I try to explain how to write the HTML code for including a source code list of another language (In this case, it's makefile).
Unluckily, I can only get the background, but not the syntax highlighted. I don't know the cause of the problem. Anyways, everyone should be able to do it on a simple web page, and I've achieved my aim: to know how to make use of highlight.js. We should treasure what we already have before seeking something new. Maybe I do too many things on this template. What's below shows how it fails.
def somefunc(param1='', param2=0):
    r'''A docstring'''
    if param1 > param2: # interesting
        print 'Gre\'ater'
    return (param2 - param1 + 1) or None

class SomeClass:

>>> message = '''interpreter
... prompt'''
Code copied from the live demo of highlight.js.

No comments:

Post a Comment