Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parse issue titles with code #92

Merged
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 9 additions & 0 deletions doc-source/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,15 @@ Changelog
===============


Unreleased
--------------

Bugs Fixed
^^^^^^^^^^^

* :mod:`sphinx_toolbox.github` now correctly parses issue titles containing code and quote characters. Reported by :github:user:`arisp99` in :github:issue:`91`.


2.18.0
--------------

Expand Down
5 changes: 4 additions & 1 deletion sphinx_toolbox/github/issues.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@

# stdlib
import warnings
import xml.sax.saxutils
from typing import Any, Dict, List, Optional, Tuple, Union

# 3rd party
Expand Down Expand Up @@ -326,6 +327,8 @@ def get_issue_title(issue_url: str) -> Optional[str]:

if r.status_code == 200:
soup = BeautifulSoup(r.content, "html5lib")
return soup.find_all("span", attrs={"class": "js-issue-title"})[0].contents[0].strip().strip()
content = soup.find_all("span", attrs={"class": "js-issue-title"})[0].text
content = xml.sax.saxutils.escape(content).replace('"', """)
return content.strip()

return None
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,9 @@ sphinx-toolbox Demo - GitHub Issues
:source:`sphinx_toolbox/source.py`

:source:`sphinx_toolbox/more_autodoc/__init__.py`

Issue with code in its title: :github:issue:`10241 <sphinx-doc/sphinx>`.

Issue with code in the beginning of the title: :github:issue:`9575 <sphinx-doc/sphinx>`.

Issue with HTML entities in title: :github:issue:`56 <sphinx-toolbox/toctree_plus>`.
12 changes: 11 additions & 1 deletion tests/test_issues_output/test_source_output.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def test_output_github(github_source_page: BeautifulSoup, html_regression: HTMLR
assert "sphinx-toolbox Demo - GitHub Issues" == title

links = github_source_page.select('p')
assert len(links) == 7
assert len(links) == 10

assert links[1] == links[2]

Expand All @@ -50,6 +50,16 @@ def test_output_github(github_source_page: BeautifulSoup, html_regression: HTMLR
'href="https://github.com/domdfcoding/sphinx-toolbox/blob/master/sphinx_toolbox/source.py">sphinx_toolbox/source.py</a></p>',
'<p><a class="reference external" '
'href="https://github.com/domdfcoding/sphinx-toolbox/blob/master/sphinx_toolbox/more_autodoc/__init__.py">sphinx_toolbox/more_autodoc/__init__.py</a></p>',
'<p>Issue with code in its title: <abbr title="Unable to install latest '
'version of flake8 and Sphinx together"><a class="reference external" '
'href="https://github.com/sphinx-doc/sphinx/issues/10241">sphinx-doc/sphinx#10241</a></abbr>.</p>',
'<p>Issue with code in the beginning of the title: <abbr '
'title=\'autodoc_typehints = "description" causes autoclass to put a return '
'type\'><a class="reference external" '
'href="https://github.com/sphinx-doc/sphinx/issues/9575">sphinx-doc/sphinx#9575</a></abbr>.</p>',
'<p>Issue with HTML entities in title: <abbr title="RFE: please provide '
'support for jinja2 &gt;= 3.1"><a class="reference external" '
'href="https://github.com/sphinx-toolbox/toctree_plus/issues/56">sphinx-toolbox/toctree_plus#56</a></abbr>.</p>',
]

html_regression.check(github_source_page, jinja2=True)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,33 @@ <h1>
sphinx_toolbox/more_autodoc/__init__.py
</a>
</p>
<p>
Issue with code in its title:
<abbr title="Unable to install latest version of flake8 and Sphinx together">
<a class="reference external" href="https://github.com/sphinx-doc/sphinx/issues/10241">
sphinx-doc/sphinx#10241
</a>
</abbr>
.
</p>
<p>
Issue with code in the beginning of the title:
<abbr title='autodoc_typehints = "description" causes autoclass to put a return type'>
<a class="reference external" href="https://github.com/sphinx-doc/sphinx/issues/9575">
sphinx-doc/sphinx#9575
</a>
</abbr>
.
</p>
<p>
Issue with HTML entities in title:
<abbr title="RFE: please provide support for jinja2 &gt;= 3.1">
<a class="reference external" href="https://github.com/sphinx-toolbox/toctree_plus/issues/56">
sphinx-toolbox/toctree_plus#56
</a>
</abbr>
.
</p>
</div>
</div>
</div>
Expand Down