Added more pygments options for code blocks

This commit is contained in:
SDGSDG 2013-08-05 19:53:32 -07:00
commit ece437f8fd
17 changed files with 196 additions and 16 deletions

View file

@ -18,3 +18,56 @@ Testing sourcecode directive
Lovely.
Testing more sourcecode directives
----------------------------------
.. sourcecode:: python
:anchorlinenos:
:classprefix: testing
:hl_lines: 10,11,12
:lineanchors: foo
:linenos: inline
:linenospecial: 2
:linenostart: 8
:linenostep: 2
:lineseparator: <br>
:linespans: foo
:nobackground:
def run(self):
self.assert_has_content()
try:
lexer = get_lexer_by_name(self.arguments[0])
except ValueError:
# no lexer found - use the text one instead of an exception
lexer = TextLexer()
if ('linenos' in self.options and
self.options['linenos'] not in ('table', 'inline')):
self.options['linenos'] = 'table'
for flag in ('nowrap', 'nobackground', 'anchorlinenos'):
if flag in self.options:
self.options[flag] = True
# noclasses should already default to False, but just in case...
formatter = HtmlFormatter(noclasses=False, **self.options)
parsed = highlight('\n'.join(self.content), lexer, formatter)
return [nodes.raw('', parsed, format='html')]
Lovely.
Testing even more sourcecode directives
---------------------------------------
.. sourcecode:: python
:linenos: table
:nowrap:
formatter = self.options and VARIANTS[self.options.keys()[0]]
Lovely.