Add language and linenos options to literalinclude directive.

This commit is contained in:
Georg Brandl
2008-03-16 11:09:32 +00:00
parent 06dd99e1a1
commit e40037d438
3 changed files with 8 additions and 0 deletions

View File

@@ -677,8 +677,14 @@ def literalinclude_directive(name, arguments, options, content, lineno,
else:
retnode = nodes.literal_block(text, text, source=fn)
retnode.line = 1
if options.get('language', ''):
retnode['language'] = options['language']
if 'linenos' in options:
retnode['linenos'] = True
return [retnode]
literalinclude_directive.options = {'linenos': directives.flag,
'language': directives.unchanged}
literalinclude_directive.content = 0
literalinclude_directive.arguments = (1, 0, 0)
directives.register_directive('literalinclude', literalinclude_directive)

View File

@@ -183,6 +183,7 @@ class HTMLTranslator(BaseTranslator):
if node.has_key('language'):
# code-block directives
lang = node['language']
if node.has_key('linenos'):
linenos = node['linenos']
self.body.append(self.highlighter.highlight_block(node.rawsource, lang, linenos))
raise nodes.SkipNode

View File

@@ -656,6 +656,7 @@ class LaTeXTranslator(nodes.NodeVisitor):
if node.has_key('language'):
# code-block directives
lang = node['language']
if node.has_key('linenos'):
linenos = node['linenos']
hlcode = self.highlighter.highlight_block(code, lang, linenos)
# workaround for Unicode issue