diff options
-rw-r--r-- | docs/src/index.txt | 2 | ||||
-rw-r--r-- | docs/src/integrate.txt | 17 | ||||
-rw-r--r-- | docs/src/rstdirective.txt | 71 | ||||
-rw-r--r-- | external/rst-directive.py | 3 |
4 files changed, 22 insertions, 71 deletions
diff --git a/docs/src/index.txt b/docs/src/index.txt index f2a7cfc7..1fad0f03 100644 --- a/docs/src/index.txt +++ b/docs/src/index.txt @@ -48,7 +48,7 @@ Welcome to the Pygments documentation. - `Using Pygments with MoinMoin <moinmoin.txt>`_ - - `Using Pygments in a other applications <integrate.txt>`_ + - `Using Pygments in other contexts <integrate.txt>`_ - About Pygments diff --git a/docs/src/integrate.txt b/docs/src/integrate.txt index ca5f9f65..fcaec223 100644 --- a/docs/src/integrate.txt +++ b/docs/src/integrate.txt @@ -1,6 +1,8 @@ -====================================== -Using Pygments in various applications -====================================== +.. -*- mode: rst -*- + +=================================== +Using Pygments in various scenarios +=================================== PyGtk ----- @@ -16,3 +18,12 @@ Wordpress He also has a snippet that shows how to use Pygments in WordPress: http://lucumr.pocoo.org/cogitations/2007/05/30/pygments-in-wordpress/ + +Markdown +-------- + +Since Pygments 0.9, the distribution ships Markdown_ preprocessor sample code +that uses Pygments to render source code in `external/markdown-processor.py`. +You can copy and adapt it to your liking. + +.. _Markdown: http://www.freewisdom.org/projects/python-markdown/
\ No newline at end of file diff --git a/docs/src/rstdirective.txt b/docs/src/rstdirective.txt index 28a6549d..9d159fda 100644 --- a/docs/src/rstdirective.txt +++ b/docs/src/rstdirective.txt @@ -1,3 +1,5 @@ +.. -*- mode: rst -*- + ================================ Using Pygments in ReST documents ================================ @@ -9,72 +11,8 @@ samples or snippets. You can easily enable Pygments support for your ReST texts using a custom directive -- this is also how this documentation displays source code. -Add this code to the script you use for building the HTML documentation: - -.. sourcecode:: python - - from docutils import nodes - from docutils.parsers.rst import directives - from pygments import highlight - from pygments.lexers import get_lexer_by_name - from pygments.formatters import HtmlFormatter - - pygments_formatter = HtmlFormatter() - - def pygments_directive(name, arguments, options, content, lineno, - content_offset, block_text, state, state_machine): - try: - lexer = get_lexer_by_name(arguments[0]) - except ValueError: - # no lexer found - use the text one instead of an exception - lexer = get_lexer_by_name('text') - parsed = highlight(u'\n'.join(content), lexer, pygments_formatter) - return [nodes.raw('', parsed, format='html')] - pygments_directive.arguments = (1, 0, 1) - pygments_directive.content = 1 - directives.register_directive('sourcecode', pygments_directive) - -Now you should be able to use Pygments to highlight source code in your ReST -files using this syntax:: - - .. sourcecode:: language - - your code here - -If you want to have two or more variants of the directive, you can utilize -ReST *directive options*, like so: - -.. sourcecode:: python - - normal_fmter = HtmlFormatter() - lineno_fmter = HtmlFormatter(linenos=True) - - def pygments_directive(name, arguments, options, content, lineno, - content_offset, block_text, state, state_machine): - try: - lexer = get_lexer_by_name(arguments[0]) - except ValueError: - # no lexer found - use the text one instead of an exception - lexer = get_lexer_by_name('text') - formatter = ('linenos' in options) and lineno_fmter or normal_fmter - parsed = highlight(u'\n'.join(content), lexer, formatter) - return [nodes.raw('', parsed, format='html')] - pygments_directive.arguments = (1, 0, 1) - pygments_directive.content = 1 - pygments_directive.options = {'linenos': directives.flag} - directives.register_directive('sourcecode', pygments_directive) - -And use it like so:: - - .. sourcecode:: language - :linenos: - - the code starts here... - -to get line numbers (to use the normal formatter, just leave out the option -like above). - -Look at the `directive documentation`_ to get all the gory details. +From Pygments 0.9, the directive is shipped in the distribution as +`external/rst-directive.py`. You can copy and adapt this code to your liking. *Loosely related note:* The ReST lexer now recognizes ``.. sourcecode::`` and @@ -82,4 +20,3 @@ Look at the `directive documentation`_ to get all the gory details. if the `handlecodeblocks` option is true. .. _ReST: http://docutils.sf.net/rst.html -.. _directive documentation: http://docutils.sourceforge.net/docs/howto/rst-directives.html diff --git a/external/rst-directive.py b/external/rst-directive.py index 168f80f5..73dfceef 100644 --- a/external/rst-directive.py +++ b/external/rst-directive.py @@ -25,7 +25,10 @@ My code goes here. + Look at the `directive documentation`_ to get all the gory details. + .. _Docutils: http://docutils.sf.net/ + .. _directive documentation: http://docutils.sourceforge.net/docs/howto/rst-directives.html :copyright: 2007 by Georg Brandl. :license: BSD, see LICENSE for more details. |