Merge pull request #6007 from tk0miya/5871_fix_texinfo_period

Allow periods in texinfo node names
This commit is contained in:
Takeshi KOMIYA 2019-02-03 19:19:24 +09:00 committed by GitHub
commit a8777f6c01
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 24 additions and 1 deletions

View File

@ -34,6 +34,7 @@ Bugs fixed
:file:`parskip.sty`
* #5958: versionadded directive causes crash with Python 3.5.0
* #5995: autodoc: autodoc_mock_imports conflict with metaclass on Python 3.7
* #5871: texinfo: a section title ``.`` is not allowed
Testing
--------

View File

@ -384,9 +384,12 @@ class TexinfoTranslator(nodes.NodeVisitor):
def escape_id(self, s):
# type: (unicode) -> unicode
"""Return an escaped string suitable for node names and anchors."""
bad_chars = ',:.()'
bad_chars = ',:()'
for bc in bad_chars:
s = s.replace(bc, ' ')
if re.search('[^ .]', s):
# remove DOTs if name contains other characters
s = s.replace('.', ' ')
s = ' '.join(s.split()).strip()
return self.escape(s)

View File

@ -15,10 +15,12 @@ import re
from subprocess import Popen, PIPE
import pytest
from mock import Mock
from six import PY3
from test_build_html import ENV_WARNINGS
from sphinx.testing.util import remove_unicode_literals, strip_escseq
from sphinx.util.docutils import new_document
from sphinx.writers.texinfo import TexinfoTranslator
@ -93,3 +95,20 @@ def test_texinfo_citation(app, status, warning):
'This is a citation\n') in output
assert ('@anchor{index cite2}@anchor{2}@w{(CITE2)} \n'
'This is a multiline citation\n') in output
@pytest.mark.sphinx('texinfo')
def test_texinfo_escape_id(app, status, warning):
settings = Mock(title='',
texinfo_dir_entry='',
texinfo_elements={})
document = new_document('', settings)
translator = app.builder.create_translator(document, app.builder)
assert translator.escape_id('Hello world') == 'Hello world'
assert translator.escape_id('Hello world') == 'Hello world'
assert translator.escape_id('Hello Sphinx world') == 'Hello Sphinx world'
assert translator.escape_id('Hello:world') == 'Hello world'
assert translator.escape_id('Hello(world)') == 'Hello world'
assert translator.escape_id('Hello world.') == 'Hello world'
assert translator.escape_id('.') == '.'