mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
PY-9795 In rendered docstring replace "--" and "---" with "–" and "—" respectively
Greater number of consecutive dashes are replaces with mdashes first, the same way as Sphinx does it, e.g. "----" is substituted with "—-". Text is left untouched inside literal fragments and literal blocks.
This commit is contained in:
@@ -3,7 +3,7 @@ import sys
|
||||
|
||||
from docutils import nodes
|
||||
from docutils.core import publish_string
|
||||
from docutils.nodes import Text, field_body, field_name, rubric, SkipNode
|
||||
from docutils.nodes import Text, field_body, field_name, rubric
|
||||
from docutils.writers.html4css1 import HTMLTranslator
|
||||
from epydoc.markup import DocstringLinker
|
||||
from epydoc.markup.restructuredtext import ParsedRstDocstring, _EpydocHTMLTranslator, \
|
||||
@@ -173,12 +173,21 @@ class RestHTMLTranslator(_EpydocHTMLTranslator):
|
||||
self.body.append(text)
|
||||
else:
|
||||
self.body.append(node_text)
|
||||
raise SkipNode
|
||||
raise nodes.SkipNode
|
||||
|
||||
def depart_problematic(self, node):
|
||||
if not self._is_text_wrapper(node):
|
||||
return HTMLTranslator.depart_problematic(self, node)
|
||||
|
||||
def visit_Text(self, node):
|
||||
text = node.astext()
|
||||
encoded = self.encode(text)
|
||||
if not isinstance(node.parent, (nodes.literal, nodes.literal_block)):
|
||||
encoded = encoded.replace('---', '—').replace('--', '–')
|
||||
if self.in_mailto and self.settings.cloak_email_addresses:
|
||||
encoded = self.cloak_email(encoded)
|
||||
self.body.append(encoded)
|
||||
|
||||
def _is_text_wrapper(self, node):
|
||||
return len(node.children) == 1 and isinstance(node.children[0], Text)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user