La macro <<code>>
The <<code>>
macro allows you to put source code into articles.
A simple example:
<<code>> from reversion.models import Revision from .helpers import ProcessedContent class Node(models.Model): language = models.CharField(max_length=10, default='en-us') <</code>>
...will display as:
from reversion.models import Revision from .helpers import ProcessedContent class Node(models.Model): language = models.CharField(max_length=10, default='en-us')
<<code>>
and links
The <<code>>
macro does not play nice with links. If you want to have inline code link to something else, use ##...##
.
For example, use:
##[[insert|INSERT]]##
instead of
[[insert|<<code>>INSERT<</code>>]]
or
<<code>>[[insert|INSERT]]<</code>>
Syntax Highlighting
The <<code>>
macro also allows you to syntax highlight code. Add syntax highlighting to the above python example like so:
<<code lang=python>> from reversion.models import Revision from .helpers import ProcessedContent class Node(models.Model): language = models.CharField(max_length=10, default='en-us') <</code>>
from reversion.models import Revision from .helpers import ProcessedContent class Node(models.Model): language = models.CharField(max_length=10, default='en-us')
Inline or Block Text
When using the <<code>>
macro with the lang=
attribute, you can also specify whether you want the code inline with the text that surrounds it, or to have it display in a block. (The Creole parser will attempt to guess what you want if you don't specify this attribute.)
Valid values are true
and false
.
Here is some <<code lang=c inline=true>>true inline code<</code>>.
Here is some true inline code
.
Here is some <<code lang=c inline=false>>false inline code<</code>>.
Here is some
false inline code
.
Here is some <<code lang=c inline=none>>none inline code<</code>>.
Here is some
none inline code
.
Supported Languages for Syntax Highlighting
Language | Allowed Short Name(s) |
---|---|
JavaScript+Mako | js+mako, javascript+mako |
Brainfuck | brainfuck, bf |
HTML+Cheetah | html+cheetah, html+spitfire |
Bash | bash, sh, ksh |
CSS+Myghty | css+myghty |
Coldufsion HTML | cfm |
Smarty | smarty |
ApacheConf | apacheconf, aconf, apache |
Java | java |
JavaScript+Genshi Text | js+genshitext, js+genshi, javascript+genshitext, javascript+genshi |
Erlang | erlang |
CoffeeScript | coffee-script, coffeescript |
ANTLR With ActionScript Target | antlr-as, antlr-actionscript |
d-objdump | d-objdump |
CSS+Ruby | css+erb, css+ruby |
MySQL | mysql |
C++ | cpp, c++ |
XML+Smarty | xml+smarty |
Felix | felix, flx |
CMake | cmake |
Mako | mako |
Python | python, py |
JavaScript+Myghty | js+myghty, javascript+myghty |
XML+Mako | xml+mako |
Boo | boo |
ActionScript | as, actionscript |
VB.net | vb.net, vbnet |
SquidConf | squidconf, squid.conf, squid |
D | d |
Logtalk | logtalk |
BBCode | bbcode |
Haml | haml, HAML |
MuPAD | mupad |
XML+Ruby | xml+erb, xml+ruby |
Debian Control file | control |
RHTML | rhtml, html+erb, html+ruby |
JavaScript+Cheetah | js+cheetah, javascript+cheetah, js+spitfire, javascript+spitfire |
Python Traceback | pytb |
cfstatement | cfs |
Ada | ada, ada95ada2005 |
objdump | objdump |
CSS+Mako | css+mako |
Gherkin | Cucumber, cucumber, Gherkin, gherkin |
Ragel in Java Host | ragel-java |
Io | io |
Vala | vala, vapi |
Haskell | haskell, hs |
Lua | lua |
Sass | sass, SASS |
ANTLR With ObjectiveC Target | antlr-objc |
XML | xml |
Groff | groff, nroff, man |
GLSL | glsl |
Genshi Text | genshitext |
Objective-J | objective-j, objectivej, obj-j, objj |
GAS | gas |
Python console session | pycon |
MXML | mxml |
XML+Cheetah | xml+cheetah, xml+spitfire |
Go | go |
Ragel in C Host | ragel-c |
aspx-cs | aspx-cs |
Ragel in Ruby Host | ragel-ruby, ragel-rb |
HTML+Genshi | html+genshi, html+kid |
Perl | perl, pl |
INI | ini, cfg |
c-objdump | c-objdump |
Tcsh | tcsh, csh |
RConsole | rconsole, rout |
CSS+Smarty | css+smarty |
ANTLR With C# Target | antlr-csharp, antlr-c# |
Darcs Patch | dpatch |
LLVM | llvm |
Nginx configuration file | nginx |
AppleScript | applescript |
Text only | text |
Literate Haskell | lhs, literate-haskell |
PHP | php, php3, php4, php5 |
MiniD | minid |
Ooc | ooc |
SQL | sql |
NASM | nasm |
Debian Sourcelist | sourceslist, sources.list |
Delphi | delphi, pas, pascal, objectpascal |
aspx-vb | aspx-vb |
HTML+Evoque | html+evoque |
NumPy | numpy |
Modula-2 | modula2, m2 |
HTML+Django/Jinja | html+django, html+jinja |
CSS+PHP | css+php |
VimL | vim |
CSS+Genshi Text | css+genshitext, css+genshi |
Ragel | ragel |
XML+Evoque | xml+evoque |
haXe | hx, haXe |
Redcode | redcode |
Django/Jinja | django, jinja |
Scala | scala |
Lighttpd configuration file | lighty, lighttpd |
Ragel in D Host | ragel-d |
Ruby irb session | rbcon, irb |
CSS | css |
JavaScript+Smarty | js+smarty, javascript+smarty |
Asymptote | asy, asymptote |
XML+PHP | xml+php |
Fortran | fortran |
Gnuplot | gnuplot |
REBOL | rebol |
ERB | erb |
Befunge | befunge |
Dylan | dylan |
MoinMoin/Trac Wiki markup | trac-wiki, moin |
Matlab | matlab, octave |
C | c |
HTML | html |
Genshi | genshi, kid, xml+genshi, xml+kid |
reStructuredText | rst, rest, restructuredtext |
IRC logs | irc |
Prolog | prolog |
CSS+Django/Jinja | css+django, css+jinja |
Smalltalk | smalltalk, squeak |
YAML | yaml |
HTML+Myghty | html+myghty |
Makefile | make, makefile, mf, bsdmake |
XSLT | xslt |
S | splus, s, r |
sqlite3con | sqlite3 |
OCaml | ocaml |
Gettext Catalog | pot, po |
Ruby | rb, ruby |
HTML+Smarty | html+smarty |
POVRay | pov |
Ragel in CPP Host | ragel-cpp |
Evoque | evoque |
Java Server Page | jsp |
ABAP | abap |
HTML+Mako | html+mako |
Diff | diff, udiff |
Matlab session | matlabsession |
HTML+PHP | html+php |
Python 3.0 Traceback | py3tb |
ANTLR With Java Target | antlr-java |
JavaScript+Ruby | js+erb, javascript+erb, js+ruby, javascript+ruby |
Makefile | basemake |
ANTLR With Python Target | antlr-python |
cpp-objdump | cpp-objdump, c++-objdumb, cxx-objdump |
Python 3 | python3, py3 |
Batchfile | bat |
ANTLR | antlr |
JavaScript+Django/Jinja | js+django, javascript+django, js+jinja, javascript+jinja |
Cython | cython, pyx |
Scheme | scheme, scm |
Erlang erl session | erl |
Clojure | clojure, clj |
Modelica | modelica |
ANTLR With Perl Target | antlr-perl |
Myghty | myghty |
Tcl | tcl |
MOOCode | moocode |
Newspeak | newspeak |
Bash Session | console |
Raw token data | raw |
C# | csharp, c# |
TeX | tex, latex |
Cheetah | cheetah, spitfire |
Objective-C | objective-c, objectivec, obj-c, objc |
JavaScript | js, javascript |
Common Lisp | common-lisp, cl |
Embedded Ragel | ragel-em |
ActionScript 3 | as3, actionscript3 |
ANTLR With CPP Target | antlr-cpp |
JavaScript+PHP | js+php, javascript+php |
Ragel in Objective C Host | ragel-objc |
XML+Django/Jinja | xml+django, xml+jinja |
ANTLR With Ruby Target | antlr-ruby, antlr-rb |
XML+Myghty | xml+myghty |