Prepare code directive for inclusion in the core.
[docutils.git] / sandbox / code-block-directive / rst2latex-highlight.py
blob616ac3ce595e921be41d033dd83fdbdd7a769b21
1 #!/usr/bin/python
3 # rst2latex-highlight
4 # ===================
5 #
6 # Docutils front-end with syntax highlight.
7 #
8 # :Author: David Goodger, a Pygments author|contributor, Guenter Milde
9 # :Date: $Date: 2008-05-22 08:42:52 +0200 (Do, 22. Mai 2008) $
10 # :Copyright: This module has been placed in the public domain.
12 # This is a merge of the docutils_ `rst2latex` front end with an extension
13 # suggestion taken from the Pygments_ documentation.
15 # ::
17 """
18 A front end to docutils, producing LaTeX with syntax colouring using pygments
20 Generates LaTeX documents from standalone reStructuredText sources. Uses the
21 `Pygments` syntax highlighter to parse and mark up the content of ``..
22 code::` directives. Needs an adapted stylesheet.
23 """
25 # Requirements
26 # ------------
28 # ::
30 try:
31 import locale
32 locale.setlocale(locale.LC_ALL, '')
33 except:
34 pass
36 from docutils.core import publish_cmdline, default_description
38 # `<pygments_code_block_directive.py>`_ defines and registers a new
39 # directive `code` that uses the `Pygments`_ syntax highlighter to
40 # render code in color::
42 import pygments_code_block_directive
44 # Call the docutils publisher to render the input as latex::
46 description = __doc__ + default_description
47 publish_cmdline(writer_name='latex2e', description=description)
50 # .. References:
51 # .. _docutils: http://docutils.sf.net/
52 # .. _pygments: http://pygments.org/
53 # .. _Using Pygments in ReST documents: http://pygments.org/docs/rstdirective/