Skip to content

Commit

Permalink
Merge pull request #8472 from tk0miya/8446_escape_spaces_inside_desc_…
Browse files Browse the repository at this point in the history
…signatures

Fix #8446: html: consecutive spaces are displayed as single space
  • Loading branch information
tk0miya committed Jan 31, 2021
2 parents 434cc60 + af6ed52 commit d3101dd
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGES
Expand Up @@ -87,6 +87,7 @@ Bugs fixed
* #8123: html search: fix searching for terms containing + (Requires a custom
search language that does not split on +)
* #8665: html theme: Could not override globaltoc_maxdepth in theme.conf
* #8446: html: consecutive spaces are displayed as single space
* #8745: i18n: crashes with KeyError when translation message adds a new auto
footnote reference
* #4304: linkcheck: Fix race condition that could lead to checking the
Expand Down
2 changes: 2 additions & 0 deletions sphinx/writers/html.py
Expand Up @@ -124,8 +124,10 @@ def depart_desc(self, node: Element) -> None:
def visit_desc_signature(self, node: Element) -> None:
# the id is set automatically
self.body.append(self.starttag(node, 'dt'))
self.protect_literal_text += 1

def depart_desc_signature(self, node: Element) -> None:
self.protect_literal_text -= 1
if not node.get('is_multiline'):
self.add_permalink_ref(node, _('Permalink to this definition'))
self.body.append('</dt>\n')
Expand Down
2 changes: 2 additions & 0 deletions sphinx/writers/html5.py
Expand Up @@ -95,8 +95,10 @@ def depart_desc(self, node: Element) -> None:
def visit_desc_signature(self, node: Element) -> None:
# the id is set automatically
self.body.append(self.starttag(node, 'dt'))
self.protect_literal_text += 1

def depart_desc_signature(self, node: Element) -> None:
self.protect_literal_text -= 1
if not node.get('is_multiline'):
self.add_permalink_ref(node, _('Permalink to this definition'))
self.body.append('</dt>\n')
Expand Down
10 changes: 6 additions & 4 deletions tests/test_build_html.py
Expand Up @@ -178,8 +178,8 @@ def test_html4_output(app, status, warning):
],
'autodoc.html': [
(".//dl[@class='py class']/dt[@id='autodoc_target.Class']", ''),
(".//dl[@class='py function']/dt[@id='autodoc_target.function']/em/span", r'\*\*'),
(".//dl[@class='py function']/dt[@id='autodoc_target.function']/em/span", r'kwds'),
(".//dl[@class='py function']/dt[@id='autodoc_target.function']/em/span/span", r'\*\*'),
(".//dl[@class='py function']/dt[@id='autodoc_target.function']/em/span/span", r'kwds'),
(".//dd/p", r'Return spam\.'),
],
'extapi.html': [
Expand Down Expand Up @@ -279,8 +279,10 @@ def test_html4_output(app, status, warning):
'objects.html': [
(".//dt[@id='mod.Cls.meth1']", ''),
(".//dt[@id='errmod.Error']", ''),
(".//dt/code", r'long\(parameter,\s* list\)'),
(".//dt/code", 'another one'),
(".//dt/code/span", r'long\(parameter,'),
(".//dt/code/span", r'list\)'),
(".//dt/code/span", 'another'),
(".//dt/code/span", 'one'),
(".//a[@href='#mod.Cls'][@class='reference internal']", ''),
(".//dl[@class='std userdesc']", ''),
(".//dt[@id='userdesc-myobj']", ''),
Expand Down
4 changes: 2 additions & 2 deletions tests/test_ext_intersphinx.py
Expand Up @@ -250,10 +250,10 @@ def test_missing_reference_cppdomain(tempdir, app, status, warning):
'<span class="pre">Bar</span></code></a>' in html)
assert ('<a class="reference external"'
' href="https://docs.python.org/index.html#foons"'
' title="(in foo v2.0)">foons</a>' in html)
' title="(in foo v2.0)"><span class="pre">foons</span></a>' in html)
assert ('<a class="reference external"'
' href="https://docs.python.org/index.html#foons_bartype"'
' title="(in foo v2.0)">bartype</a>' in html)
' title="(in foo v2.0)"><span class="pre">bartype</span></a>' in html)


def test_missing_reference_jsdomain(tempdir, app, status, warning):
Expand Down

0 comments on commit d3101dd

Please sign in to comment.