Skip to content

Commit

Permalink
Parse issue titles with code (#92)
Browse files Browse the repository at this point in the history
* Parse issue titles with code

* Format code

* Handle issue titles with quotes and add tests.

* Strip whitespace from issue title.

* Add changelog entry.

Co-authored-by: Dominic Davis-Foster <dominic@davis-foster.co.uk>
  • Loading branch information
arisp99 and domdfcoding committed Apr 20, 2022
1 parent 2b4430b commit b13352a
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 2 deletions.
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('"', "&quot;")
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 @@ -24,7 +24,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 @@ -49,6 +49,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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,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

0 comments on commit b13352a

Please sign in to comment.