Highlight

For all the times that you want good looking code on your site or in your posts: Highlight will lex and, well, highlight your markdown code snippets for you.

Since highlight internally utilizes pygments, a wide variety of lexers and styles are supported.

read full documentation

how it's done

markdown supports code blocks by default, as well as specifying the language used within that code block:

1
2
3
4
```python
def my_func():
    pass
```

Various config options are supported (see the docs), the most important ones of which are probably:

If no global, page-level, or code-block-level lexer is set, pygments will guess the language, which is pretty hit-and-miss.

what you get

Let's say Highlight was configured like this:

1
2
3
HIGHLIGHT:
  THEME: tango
  ASSETS_DIR: res

(which happens to be the case for this very site), and the <head> of the page's template imports the stylesheet:

1
<link rel="stylesheet" href="/res/highlight/tango.css" media="screen">

Inside our markdown file, we have this simple fib-function:

1
2
3
4
5
6
7
```python
def fib_to(n):
    fibs = [0, 1]
    for i in range(2, n+1):
        fibs.append(fibs[-1] + fibs[-2])
    return fibs
```

Then the lexed & highlighted output will look like this:

1
2
3
4
5
def fib_to(n):
    fibs = [0, 1]
    for i in range(2, n+1):
        fibs.append(fibs[-1] + fibs[-2])
    return fibs