Skip to content

Commit

Permalink
Remove LaTeX url command from tooltips (#306)
Browse files Browse the repository at this point in the history
Closes #305
  • Loading branch information
mcmtroffaes authored Jul 26, 2022
1 parent 4fbda63 commit 9a672e2
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 2 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@

* Add support for docutils 0.18.

* Suppress LaTeX url commands in tooltips (see issue #305, reported by
1kastner).

2.4.2 (10 April 2022)
---------------------

Expand Down
3 changes: 2 additions & 1 deletion src/sphinxcontrib/bibtex/domain.py
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,8 @@ def resolve_xref(self, env: "BuildEnvironment", fromdocname: str,
todocname=citation.bibliography_key.docname,
citation_id=citation.citation_id,
title=(
citation.tooltip_entry.text.render(plaintext)
citation.tooltip_entry.text.render(plaintext).replace(
"\\url ", "")
if citation.tooltip_entry else None
)
))
Expand Down
3 changes: 2 additions & 1 deletion test/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@

def html_citation_refs(
refid=RE_ID, label=RE_LABEL, title: Optional[str] = RE_TITLE):
title_pattern = rf' title="{title}"' if title is not None else ''
title_pattern = (
rf' title="(?P<title>{title})"' if title is not None else '')
return re.compile(
r'<a class="reference internal"'
r' href="(?P<refdoc>[^#]+)?#(?P<refid>{refid})"'
Expand Down
5 changes: 5 additions & 0 deletions test/roots/test-bibliography_url/index.rst
Original file line number Diff line number Diff line change
@@ -1,2 +1,7 @@
:cite:`one`
:cite:`two`
:cite:`three`
:cite:`four`

.. bibliography::
:all:
13 changes: 13 additions & 0 deletions test/test_bibliography.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,19 @@ def test_bibliography_url(app, warning) -> None:
assert 'aaa' + url('https://google.com/') + 'bbb' in match2.group('text')
assert url('https://youtube.com/') in match3.group('text')
assert 'URL: ' + url('https://wikipedia.org/') in match4.group('text')
# check tooltips do not contain \url command
match4 = html_citation_refs(label='Een').search(output)
match5 = html_citation_refs(label='Twe').search(output)
match6 = html_citation_refs(label='Dri').search(output)
match7 = html_citation_refs(label='Vie').search(output)
assert match4 is not None
assert match5 is not None
assert match6 is not None
assert match7 is not None
assert "\\url " not in match4.group('title')
assert "\\url " not in match5.group('title')
assert "\\url " not in match6.group('title')
assert "\\url " not in match7.group('title')


@pytest.mark.sphinx('html', testroot='bibliography_custom_ids')
Expand Down

0 comments on commit 9a672e2

Please sign in to comment.