]>
code.delx.au - gnu-emacs-elpa/blob - doc/compile-doc.py
2 # Compile document to HTML use docutils.
4 # ========================================
5 # Pygments syntax highlighting
6 # ========================================
7 from pygments
.formatters
import HtmlFormatter
9 # Set to True if you want inline CSS styles instead of classes
12 from pygments
.formatters
import HtmlFormatter
14 # The default formatter
15 DEFAULT
= HtmlFormatter(noclasses
=INLINESTYLES
)
17 # Add name -> formatter pairs for every variant you want to use
19 # 'linenos': HtmlFormatter(noclasses=INLINESTYLES, linenos=True),
22 from docutils
import nodes
23 from docutils
.parsers
.rst
import directives
25 from pygments
import highlight
26 from pygments
.lexers
import get_lexer_by_name
, TextLexer
28 def pygments_directive(name
, arguments
, options
, content
, lineno
,
29 content_offset
, block_text
, state
, state_machine
):
31 lexer
= get_lexer_by_name(arguments
[0])
33 # no lexer found - use the text one instead of an exception
35 # take an arbitrary option if more than one is given
36 formatter
= options
and VARIANTS
[options
.keys()[0]] or DEFAULT
37 parsed
= highlight(u
'\n'.join(content
), lexer
, formatter
)
38 return [nodes
.raw('', parsed
, format
='html')]
40 pygments_directive
.arguments
= (1, 0, 1)
41 pygments_directive
.content
= 1
42 pygments_directive
.options
= dict([(key
, directives
.flag
) for key
in VARIANTS
])
44 directives
.register_directive('sourcecode', pygments_directive
)
47 # ========================================
48 # Command line processing
49 # ========================================
50 from docutils
.core
import publish_cmdline
, default_description
53 description
= ('Generates (X)HTML documents from standalone reStructuredText '
54 'sources. ' + default_description
)
56 publish_cmdline(writer_name
='html', description
=description
)