Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions mkdocs/structure/pages.py
Original file line number Diff line number Diff line change
Expand Up @@ -572,8 +572,15 @@ def __init__(self) -> None:

def run(self, lines: list[str]) -> list[str]:
parser = _HTMLHandler()
parser.feed("\n".join(lines))
parser.close()
try:
parser.feed("\n".join(lines))
parser.close()
except (AssertionError, RuntimeError):
# Python's html.parser can throw AssertionError on edge-case
# markup such as "<<>>" (Python 3.13+ regression).
# RuntimeError is raised when the parser encounters deeply
# nested or otherwise problematic input.
pass
self.present_anchor_ids = parser.present_anchor_ids
return lines

Expand Down
12 changes: 12 additions & 0 deletions mkdocs/tests/structure/page_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,18 @@ def test_page_title_from_markdown_html_entity(self):
def test_page_title_from_markdown_strip_raw_html(self):
self._test_extract_title("""# Hello <b>world</b>""", expected="Hello world")

def test_raw_html_preprocessor_edge_case_markup(self):
# Regression test for https://github.com/mkdocs/mkdocs/issues/4001
# Python 3.13's html.parser throws AssertionError on "<<>>" markup.
from mkdocs.structure.pages import _RawHTMLPreprocessor as RHP

proc = RHP()
# The preprocessor should handle edge-case markup without raising.
lines = ["# Title", "", "The PDF object as an `obj<</>>endobj` text block."]
result = proc.run(lines)
self.assertEqual(result, lines)
self.assertEqual(proc.present_anchor_ids, set())

def test_page_title_from_markdown_strip_comments(self):
self._test_extract_title(
"""# foo <!-- comment with <em> --> bar""", expected="foo bar"
Expand Down
Loading