Skip to content

Commit

Permalink
Merge pull request #173 from sparkiegeek/discourse-28-header-change-172
Browse files Browse the repository at this point in the history
fix(parser): Support Discourse 2.8.14 header formatting
  • Loading branch information
jpmartinspt authored Oct 23, 2023
2 parents d831264 + b0d8bfb commit 9da26d3
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
21 changes: 13 additions & 8 deletions canonicalwebteam/discourse/parsers/base_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ def __init__(self, error):
super().__init__(error)

flask.current_app.extensions["sentry"].captureMessage(error)
pass


class BaseParser:
Expand Down Expand Up @@ -214,7 +213,7 @@ def _parse_redirect_map(self, index_soup):

if not (
location.startswith(self.url_prefix)
or validators.url(location, public=True)
or validators.url(location)
):
warnings.append(
f"Redirect map location {location} is invalid"
Expand Down Expand Up @@ -479,9 +478,12 @@ def _get_section(self, soup, title_text):
<p>Content</p>
"""
heading = soup.find(HEADER_REGEX, string=title_text)

if not heading:
for heading in soup(HEADER_REGEX):
if heading.string is None and heading.a.next == title_text:
break
elif heading.string == title_text:
break
else:
return None

heading_tag = heading.name
Expand All @@ -501,9 +503,12 @@ def _get_preamble(self, soup, break_on_title):
the heading defined in `break_on_title`,
and return it as a BeautifulSoup object
"""
heading = soup.find(HEADER_REGEX, string=break_on_title)

if not heading:
for heading in soup(HEADER_REGEX):
if heading.string is None and heading.a.next == break_on_title:
break
elif heading.string == break_on_title:
break
else:
return soup
# get all the previous contents, reversing order on insert
preamble_soup = BeautifulSoup()
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

setup(
name="canonicalwebteam.discourse",
version="5.4.2",
version="5.4.3",
author="Canonical webteam",
author_email="webteam@canonical.com",
url="https://github.com/canonical/canonicalwebteam.discourse",
Expand Down

0 comments on commit 9da26d3

Please sign in to comment.