Skip to content

Commit f157522

Browse files
committed
Fixes for Python 3.14 and fixes for deprecations
- Fix codecs deprecation - Fix issue with unclosed `<![` - Fix issue with unclosed HTML tag `<foo` Fixes #1537
1 parent 3870f20 commit f157522

File tree

5 files changed

+21
-6
lines changed

5 files changed

+21
-6
lines changed

docs/changelog.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,14 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
99
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
1010
See the [Contributing Guide](contributing.md) for details.
1111

12+
## Unreleased
13+
14+
### Fixed
15+
16+
* Fix `codecs` deprecation.
17+
* Fix issue with unclosed `<![` in Python 3.14.
18+
* Fix issue with unclosed HTML tag `<foo` and Python 3.14.
19+
1220
## [3.8.1] - 2025-06-18
1321

1422
### Fixed

markdown/__main__.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121

2222
import sys
2323
import optparse
24-
import codecs
2524
import warnings
2625
import markdown
2726
try:
@@ -100,7 +99,7 @@ def parse_options(args=None, values=None):
10099

101100
extension_configs = {}
102101
if options.configfile:
103-
with codecs.open(
102+
with open(
104103
options.configfile, mode="r", encoding=options.encoding
105104
) as fp:
106105
try:

markdown/core.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -417,7 +417,7 @@ def convertFile(
417417
# Read the source
418418
if input:
419419
if isinstance(input, str):
420-
input_file = codecs.open(input, mode="r", encoding=encoding)
420+
input_file = open(input, mode="r", encoding=encoding)
421421
else:
422422
input_file = codecs.getreader(encoding)(input)
423423
text = input_file.read()

markdown/extensions/md_in_html.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,10 @@ def parse_html_declaration(self, i: int) -> int:
283283
if self.rawdata[i:i+3] == '<![' and not self.rawdata[i:i+9] == '<![CDATA[':
284284
# We have encountered the bug in #1534 (Python bug `gh-77057`).
285285
# Provide an override until we drop support for Python < 3.13.
286-
return self.parse_bogus_comment(i)
286+
result = self.parse_bogus_comment(i)
287+
if result == -1:
288+
self.handle_data(self.rawdata[i:i + 1])
289+
return i + 1
287290
# The same override exists in `HTMLExtractor` without the check
288291
# for `mdstack`. Therefore, use parent of `HTMLExtractor` instead.
289292
return super(HTMLExtractor, self).parse_html_declaration(i)

markdown/htmlparser.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,11 @@ def parse_html_declaration(self, i: int) -> int:
278278
if self.rawdata[i:i+3] == '<![' and not self.rawdata[i:i+9] == '<![CDATA[':
279279
# We have encountered the bug in #1534 (Python bug `gh-77057`).
280280
# Provide an override until we drop support for Python < 3.13.
281-
return self.parse_bogus_comment(i)
281+
result = self.parse_bogus_comment(i)
282+
if result == -1:
283+
self.handle_data(self.rawdata[i:i + 1])
284+
return i + 1
285+
return result
282286
return super().parse_html_declaration(i)
283287
# This is not the beginning of a raw block so treat as plain data
284288
# and avoid consuming any tags which may follow (see #1066).
@@ -313,7 +317,8 @@ def parse_starttag(self, i: int) -> int: # pragma: no cover
313317
self.__starttag_text = None
314318
endpos = self.check_for_whole_start_tag(i)
315319
if endpos < 0:
316-
return endpos
320+
self.handle_data(self.rawdata[i:i + 1])
321+
return i + 1
317322
rawdata = self.rawdata
318323
self.__starttag_text = rawdata[i:endpos]
319324

0 commit comments

Comments
 (0)