summaryrefslogtreecommitdiff
path: root/sphinx/directives/code.py
diff options
context:
space:
mode:
authorJames Knight <james.d.knight@live.com>2018-10-04 02:55:35 -0400
committerJames Knight <james.d.knight@live.com>2019-02-16 22:14:30 -0500
commit0ded648c1a1aa4f7649d89f209f070cef5bbaa7f (patch)
tree2de65777ec9885a5f14862b8f803ec4327421ab7 /sphinx/directives/code.py
parent63ccc34475639efd44d324f50e12e9697edc628a (diff)
downloadsphinx-git-0ded648c1a1aa4f7649d89f209f070cef5bbaa7f.tar.gz
directive-code: do not force linenos value on run
Now that `highlightlang` directive is deprecated [1], the `linenothreshold` option is to be used via the `highlight` directive. The `highlight` directive will walk-through literal blocks to apply a `linenos` value if: 1) The literal block has not been explicitly configured with the `linenos` option. 2) If there is enough content (when comparing literal block's line count to `linenothreshold`) that `linenos` should be explicitly enabled or disabled [2]. While the `hightlight` directive should be able to explicitly define if a literal block needs to enable line numbers, the logic is always ignored since the code block and literal include directives already configures `linenos` when checking for line number-specific options on the node [3][4]. This effectively prevents `linenothreshold` from being used. To allow `linenothreshold` to be used in literal blocks, this commit disables the explicit configuration `linenos` on a literal block instance when the `CodeBlock` and `LiteralInclude` directives are processed. [1]: b35198d8475fe89aaf9a5224a9832fb394e73cca [2]: https://github.com/sphinx-doc/sphinx/blob/v1.8.1/sphinx/transforms/post_transforms/code.py#L95-L97 [3]: https://github.com/sphinx-doc/sphinx/blob/v1.8.1/sphinx/directives/code.py#L156-L157 [4]: https://github.com/sphinx-doc/sphinx/blob/v1.8.1/sphinx/directives/code.py#L442-L444 Signed-off-by: James Knight <james.d.knight@live.com>
Diffstat (limited to 'sphinx/directives/code.py')
-rw-r--r--sphinx/directives/code.py10
1 files changed, 5 insertions, 5 deletions
diff --git a/sphinx/directives/code.py b/sphinx/directives/code.py
index 9ac704c55..73afac4ba 100644
--- a/sphinx/directives/code.py
+++ b/sphinx/directives/code.py
@@ -154,8 +154,8 @@ class CodeBlock(SphinxDirective):
code = '\n'.join(lines)
literal = nodes.literal_block(code, code) # type: nodes.Element
- literal['linenos'] = 'linenos' in self.options or \
- 'lineno-start' in self.options
+ if 'linenos' in self.options or 'lineno-start' in self.options:
+ literal['linenos'] = True
literal['classes'] += self.options.get('class', [])
if self.arguments:
# highlight language specified
@@ -451,9 +451,9 @@ class LiteralInclude(SphinxDirective):
retnode['language'] = 'udiff'
elif 'language' in self.options:
retnode['language'] = self.options['language']
- retnode['linenos'] = ('linenos' in self.options or
- 'lineno-start' in self.options or
- 'lineno-match' in self.options)
+ if ('linenos' in self.options or 'lineno-start' in self.options or
+ 'lineno-match' in self.options):
+ retnode['linenos'] = True
retnode['classes'] += self.options.get('class', [])
extra_args = retnode['highlight_args'] = {}
if 'emphasize-lines' in self.options: