diff options
author | Takeshi KOMIYA <i.tkomiya@gmail.com> | 2020-08-08 12:16:59 +0300 |
---|---|---|
committer | Takeshi KOMIYA <i.tkomiya@gmail.com> | 2020-08-08 12:16:59 +0300 |
commit | a8927bcd3e06f7d75cbd5fe53603b4a3e5b83086 (patch) | |
tree | 6d31030c5fd7d977748fba7f8acbf95af7f56f26 /sphinx/transforms | |
parent | 9969239b2255bb145052d7e5aef56e44db15cb5b (diff) | |
parent | 40bdeb2c1603abc1d7b07b3e617904f8c3fbb1fe (diff) |
Merge branch '3.x'
Diffstat (limited to 'sphinx/transforms')
-rw-r--r-- | sphinx/transforms/post_transforms/code.py | 13 |
1 files changed, 6 insertions, 7 deletions
diff --git a/sphinx/transforms/post_transforms/code.py b/sphinx/transforms/post_transforms/code.py index f6ddb521f..b5b2a95de 100644 --- a/sphinx/transforms/post_transforms/code.py +++ b/sphinx/transforms/post_transforms/code.py @@ -9,10 +9,10 @@ """ import sys -from typing import Any, Dict, List, NamedTuple, Union +from typing import Any, Dict, List, NamedTuple from docutils import nodes -from docutils.nodes import Node +from docutils.nodes import Node, TextElement from pygments.lexers import PythonConsoleLexer, guess_lexer from sphinx import addnodes @@ -94,9 +94,6 @@ class TrimDoctestFlagsTransform(SphinxTransform): default_priority = HighlightLanguageTransform.default_priority + 1 def apply(self, **kwargs: Any) -> None: - if not self.config.trim_doctest_flags: - return - for lbnode in self.document.traverse(nodes.literal_block): # type: nodes.literal_block if self.is_pyconsole(lbnode): self.strip_doctest_flags(lbnode) @@ -104,8 +101,10 @@ class TrimDoctestFlagsTransform(SphinxTransform): for dbnode in self.document.traverse(nodes.doctest_block): # type: nodes.doctest_block self.strip_doctest_flags(dbnode) - @staticmethod - def strip_doctest_flags(node: Union[nodes.literal_block, nodes.doctest_block]) -> None: + def strip_doctest_flags(self, node: TextElement) -> None: + if not node.get('trim_flags', self.config.trim_doctest_flags): + return + source = node.rawsource source = doctest.blankline_re.sub('', source) source = doctest.doctestopt_re.sub('', source) |