Skip to content

Commit 0d7a5dd

Browse files
committed
Fix unclosed comments
1 parent a823912 commit 0d7a5dd

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

docs/changelog.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ See the [Contributing Guide](contributing.md) for details.
1515
### Fixed
1616

1717
* Fix `codecs` deprecation.
18-
* Fix issue with unclosed `<![` in Python 3.14.
18+
* Fix issue with unclosed comment parsing in Python 3.14.
19+
* Fix issue with unclosed declerations in Python 3.14.
1920
* Fix issue with unclosed HTML tag `<foo` and Python 3.14.
2021

2122
## [3.8.1] - 2025-06-18

markdown/htmlparser.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,8 @@ def __init__(self, md: Markdown, *args, **kwargs):
9393

9494
self.lineno_start_cache = [0]
9595

96+
self.override_comment_update = False
97+
9698
# This calls self.reset
9799
super().__init__(*args, **kwargs)
98100
self.md = md
@@ -253,8 +255,22 @@ def handle_entityref(self, name: str):
253255
self.handle_empty_tag('&{};'.format(name), is_block=False)
254256

255257
def handle_comment(self, data: str):
258+
# Check if the comment is unclosed, if so, we need to override position
259+
# update
260+
i = self.line_offset + self.offset + len(data) + 4
261+
if self.rawdata[i:i + 3] != '-->':
262+
self.handle_data('<!--')
263+
self.override_comment_update = True
264+
return
256265
self.handle_empty_tag('<!--{}-->'.format(data), is_block=True)
257266

267+
def updatepos(self, i: int, j: int) -> int:
268+
if self.override_comment_update:
269+
self.override_comment_update = False
270+
i = 0
271+
j = 4
272+
return super().updatepos(i, j)
273+
258274
def handle_decl(self, data: str):
259275
self.handle_empty_tag('<!{}>'.format(data), is_block=True)
260276

0 commit comments

Comments
 (0)