Blog 1

Random Talk on Random Thoughts

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

| Comments |

Note: This post won’t make sense here. Refer to the original post.1

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.2

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:

1
2
3
4
hello : hello.c
	gcc -o hello hello.c
clean:
	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.

1
2
3
4
hello : hello.c
	gcc -o hello hello.c
clean:
	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.

Code copied from the live demo of highlight.js.

1
2
3
4
5
6
7
8
9
10
11
12
@requires_authorization
def somefunc(param1='', param2=0):
    r'''A docstring'''
    if param1 > param2: # interesting
        print 'Gre\'ater'
    return (param2 - param1 + 1) or None

class SomeClass:
    pass

>>> message = '''interpreter
... prompt'''

  1. Updated on 07/02/14 22:18:24 HKT. 

  2. Updated on 08/01/14 09:45:00 GMT. 

Comments