Skip to content

Commit

Permalink
fix(parser): Support Discourse 2.8.14 header formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
sparkiegeek committed Oct 20, 2023
1 parent d831264 commit 3f79a48
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 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 @@ -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

0 comments on commit 3f79a48

Please sign in to comment.