Merge pull request #6077 from tk0miya/refactor_role4

Fix :pep: and :rfc: roles are broken
This commit is contained in:
Takeshi KOMIYA 2019-02-16 01:55:19 +09:00 committed by GitHub
commit 66afbec979
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 53 additions and 10 deletions

View File

@ -277,11 +277,11 @@ class PEP(ReferenceRole):
def build_uri(self):
# type: () -> str
base_url = self.inliner.document.settings.pep_base_url
target, anchor = self.target.split('#', 1)
if anchor:
return base_url + 'pep-%04d#%s' % (int(target), anchor)
ret = self.target.split('#', 1)
if len(ret) == 2:
return base_url + 'pep-%04d#%s' % (int(ret[0]), ret[1])
else:
return base_url + 'pep-%04d' % int(target)
return base_url + 'pep-%04d' % int(ret[0])
class RFC(ReferenceRole):
@ -312,13 +312,12 @@ class RFC(ReferenceRole):
def build_uri(self):
# type: () -> str
target, anchor = self.target.split('#', 1)
base_url = (self.inliner.document.settings.rfc_base_url +
self.inliner.rfc_url % int(target))
if anchor:
return base_url + '#' + anchor
base_url = self.inliner.document.settings.rfc_base_url
ret = self.target.split('#', 1)
if len(ret) == 2:
return base_url + self.inliner.rfc_url % int(ret[0]) + '#' + ret[1]
else:
return base_url
return base_url + self.inliner.rfc_url % int(ret[0])
_amp_re = re.compile(r'(?<!&)&(?![&\s])')

View File

@ -35,6 +35,7 @@ def settings(app):
settings.env = app.builder.env
settings.env.temp_data['docname'] = 'dummy'
settings.contentsname = 'dummy'
settings.rfc_base_url = 'http://tools.ietf.org/html/'
domain_context = sphinx_domains(settings.env)
domain_context.enable()
yield settings
@ -132,6 +133,49 @@ def get_verifier(verify, verify_re):
@pytest.mark.parametrize('type,rst,html_expected,latex_expected', [
(
# pep role
'verify',
':pep:`8`',
('<p><span class="target" id="index-0"></span><a class="pep reference external" '
'href="http://www.python.org/dev/peps/pep-0008"><strong>PEP 8</strong></a></p>'),
('\\index{Python Enhancement Proposals@\\spxentry{Python Enhancement Proposals}'
'!PEP 8@\\spxentry{PEP 8}}\\sphinxhref{http://www.python.org/dev/peps/pep-0008}'
'{\\sphinxstylestrong{PEP 8}}')
),
(
# pep role with anchor
'verify',
':pep:`8#id1`',
('<p><span class="target" id="index-0"></span><a class="pep reference external" '
'href="http://www.python.org/dev/peps/pep-0008#id1">'
'<strong>PEP 8#id1</strong></a></p>'),
('\\index{Python Enhancement Proposals@\\spxentry{Python Enhancement Proposals}'
'!PEP 8\\#id1@\\spxentry{PEP 8\\#id1}}\\sphinxhref'
'{http://www.python.org/dev/peps/pep-0008\\#id1}'
'{\\sphinxstylestrong{PEP 8\\#id1}}')
),
(
# rfc role
'verify',
':rfc:`2324`',
('<p><span class="target" id="index-0"></span><a class="rfc reference external" '
'href="http://tools.ietf.org/html/rfc2324.html"><strong>RFC 2324</strong></a></p>'),
('\\index{RFC@\\spxentry{RFC}!RFC 2324@\\spxentry{RFC 2324}}'
'\\sphinxhref{http://tools.ietf.org/html/rfc2324.html}'
'{\\sphinxstylestrong{RFC 2324}}')
),
(
# rfc role with anchor
'verify',
':rfc:`2324#id1`',
('<p><span class="target" id="index-0"></span><a class="rfc reference external" '
'href="http://tools.ietf.org/html/rfc2324.html#id1">'
'<strong>RFC 2324#id1</strong></a></p>'),
('\\index{RFC@\\spxentry{RFC}!RFC 2324\\#id1@\\spxentry{RFC 2324\\#id1}}'
'\\sphinxhref{http://tools.ietf.org/html/rfc2324.html\\#id1}'
'{\\sphinxstylestrong{RFC 2324\\#id1}}')
),
(
# correct interpretation of code with whitespace
'verify_re',