diff options
author | Georg Brandl <georg@python.org> | 2014-01-11 08:44:45 +0100 |
---|---|---|
committer | Georg Brandl <georg@python.org> | 2014-01-11 08:44:45 +0100 |
commit | 269ef714f34efd6fe98a4e7bde08bfb3b4928264 (patch) | |
tree | 7e1facc5fc101e3c21bedc7a2b8446aa346ecc13 /sphinx/directives/code.py | |
parent | 5394fbb82bced4186afb3fd813e9ab1b089dce61 (diff) | |
download | sphinx-git-269ef714f34efd6fe98a4e7bde08bfb3b4928264.tar.gz |
Closes #668: Allow line numbering of ``code-block`` and ``literalinclude`` directives
#to start at an arbitrary line number, with a new ``lineno-start`` option.
Diffstat (limited to 'sphinx/directives/code.py')
-rw-r--r-- | sphinx/directives/code.py | 19 |
1 files changed, 14 insertions, 5 deletions
diff --git a/sphinx/directives/code.py b/sphinx/directives/code.py index 4d43e5ff6..7b1acfd58 100644 --- a/sphinx/directives/code.py +++ b/sphinx/directives/code.py @@ -56,6 +56,7 @@ class CodeBlock(Directive): final_argument_whitespace = False option_spec = { 'linenos': directives.flag, + 'lineno-start': int, 'emphasize-lines': directives.unchanged_required, } @@ -75,9 +76,13 @@ class CodeBlock(Directive): literal = nodes.literal_block(code, code) literal['language'] = self.arguments[0] - literal['linenos'] = 'linenos' in self.options + literal['linenos'] = 'linenos' in self.options or \ + 'lineno-start' in self.options + extra_args = literal['highlight_args'] = {} if hl_lines is not None: - literal['highlight_args'] = {'hl_lines': hl_lines} + extra_args['hl_lines'] = hl_lines + if 'lineno-start' in self.options: + extra_args['linenostart'] = self.options['lineno-start'] set_source_info(self, literal) return [literal] @@ -95,6 +100,7 @@ class LiteralInclude(Directive): final_argument_whitespace = True option_spec = { 'linenos': directives.flag, + 'lineno-start': int, 'tab-width': int, 'language': directives.unchanged_required, 'encoding': directives.encoding, @@ -204,10 +210,13 @@ class LiteralInclude(Directive): set_source_info(self, retnode) if self.options.get('language', ''): retnode['language'] = self.options['language'] - if 'linenos' in self.options: - retnode['linenos'] = True + retnode['linenos'] = 'linenos' in self.options or \ + 'lineno-start' in self.options + extra_args = retnode['highlight_args'] = {} if hl_lines is not None: - retnode['highlight_args'] = {'hl_lines': hl_lines} + extra_args['hl_lines'] = hl_lines + if 'lineno-start' in self.options: + extra_args['linenostart'] = self.options['lineno-start'] env.note_dependency(rel_filename) return [retnode] |