Change - Code Highlighting

Created on Nov. 23, 2012, 10:35 a.m. by Hevok & updated on Nov. 23, 2012, 10:36 a.m. by Hevok

Pygments is a synthax highlighter. It can be used with reST or markdown. ¶
¶
To highlight code in reST use the sourcecode directive followed by the specified language_ (e.g. python, html, django, reST):: ¶
¶
.. sourecode:: python ¶
¶
def sum(x,y): ¶
return x + y ¶
¶
Numerous languages_ are supported and can be tested by a `demo app`_: ¶
¶
.. _language: http://pygments.org/languages/ &para]
.. demo app: http://pygments.org/demo/ &para]
¶
Markdown 2.0+ has an extension system CodeHilite_ that uses Pygements. ¶
¶
.. _CodeHilite: http://freewisdom.org/projects/python-markdown/CodeHilite &para]
¶
A prerequisite is to create a style-sheet that defines color for synthax highlighting:: ¶
¶
$ pygmentize -S default -f html -a .codehilite > code.css ¶
¶
To use CodeHilite_ add the following to the template: ¶
¶
.. sourcecode:: django ¶
¶
{% load markup %} ¶
{{ entry.text|markdown:codehilite }} ¶
¶
To mark code block within the text, indent the block by 4 spaces, declare the language of the block in the first line prefixed by three subsequent colons: ¶
¶
.. sourcecode:: python ¶
¶
:::python ¶
print("Code highlighting") ¶
¶
In order to be sure that untrusted embedded HTML elements are not enabled inlcude the following instead of the above:: ¶
¶
.. sour
ecode:: django ¶
¶
{% load markup %} ¶
{{ entry.text|markdown:'safe,codehilite' }} ¶

Docutils System Messages

System Message: ERROR/3 (, line 3); backlink

Unknown target name: "language".

System Message: ERROR/3 (, line 3); backlink

Unknown target name: "languages".

System Message: ERROR/3 (, line 3); backlink

Unknown target name: "demo app".

System Message: ERROR/3 (, line 3); backlink

Unknown target name: "codehilite".

System Message: ERROR/3 (, line 3); backlink

Unknown target name: "codehilite".
Tags: rest django

Comment: Updated entry

Comment on This Data Unit