Login
or
register
Overview
Introduction
Features
Credits
License
This Wiki
Status
News
Releases
Change Log
Recent Wiki Edits
User Guide
Installation
Command Line
Using as a Module
Integration
Reporting Bugs
Advanced
Mailing List
Source Code
Test Suite
Extensions
Extensions
Writing Extensions
Available Extensions
Related Projects
CodeHilite
Anonymous users must enter
captcha
below.
Don't put anything here
Don't put anything here
Page Parameters
Page Name (for URL)
Page Title
Show Advanced Options
Category
Prototype
Don't put anything here
Page Content
###Summary The CodeHilite Extension adds code/syntax highlighting to standard Python-Markdown code blocks using [Pygments][]. [Python-Markdown]: http://www.freewisdom.org/projects/python-markdown/ [Pygments]: http://pygments.org/ ###Get the Code The code is currently available in the Python-Markdown Git [repository][] and will likely be included in the next release. [repository]: http://gitorious.org/projects/python-markdown/repos/mainline/blobs/master/mdx_codehilite.py ####Dependencies * [Python 2.3+](http://python.org) * [Markdown 1.7+](http://www.freewisdom.org/projects/python-markdown/) * [Pygments](http://pygments.org/) You will also need to [download][dl] and install the Pygments package on your `PYTHONPATH`. You will need to determine the appropriate CSS classes and create appropriate rules for them, which are either defined in or linked from the header of your HTML templates. See the excellent [documentation][] for more details. If no language is defined, Pygments will attempt to guess the language. When that fails, the code block will display as un-highlighted code. [dl]: http://pygments.org/download/ [documentation]: http://pygments.org/docs **Note:** The css and/or javascript is not included as part of this extension but shall always be provided by the end user. ####License The Markdown CodeHilite Extension is licensed under the [BSD](http://www.opensource.org/licenses/bsd-license.php) License. ###Syntax The CodeHilite Extension follows the same [syntax][] as regular Markdown code blocks, with one exception. The hiliter needs to know what language to use for the code block. There are three ways to tell the hiliter what language the code block contains and each one has a different result. [syntax]: http://daringfireball.net/projects/markdown/syntax#precode ####SheBang (with path) If the first line of the codeblock contains a shebang, the language is derived from that and line numbers are used. #!/usr/bin/python # Code goes here ... Will result in: #!/usr/bin/python # Code goes here ... ####SheBang (no path) If the first line contains a shebang, but the shebang line does not contain a path (a single `/` or even a space), then that line is removed from the code block before processing. Line numbers are used. #!python # Code goes here ... Will result in: # Code goes here ... ####Colons If the first line begins with three or more colons, the text following the colons identifies the language. The first line is removed from the code block before processing and line numbers are not used. :::python # Code goes here ... Will result in: # Code goes here ... ####When No Language is Defined CodeHilite is completely backward compatible so that if a code block is encountered that does not define a language, the block is simple wrapped in `<pre>` tags and output. Note: one exception would be that the Pygments highlighting engine will try to guess the language. Upon failure, the same behavior will happen as described here. # Code goes here ... Will result in: # Code goes here ... Lets see the source for that: <div class="codehilite" ><pre># Code goes here ... </pre></div> ###Usage From the Python interpreter: >>> import markdown >>> html = markdown.markdown(text, ['codehilite']) To use with other extensions, just add them to the list, like this: >>> html = markdown.markdown(text, ['codehilite', 'wikilink', 'footnotes']) CodeHilite can also be called from the command line using Markdown's `-x` parameter, like so: python markdown.py -x codehilite source.txt > output.html ###Forcing Line Numbers If you want every code block to have line numbers, even when using colons (`:::`) for language identification, the setting `force_linenos` is available to do so. >>> html = markdown.markdown(text, ... ['codehilite(force_linenos=True)'] ... )
Don't put anything here
Don't put anything here
About this Edit
Minor Edit
Edit Summary
Don't put anything here
Powered by
Sputnik
|
XHTML 1.1