File fix-patched-python311.patch of Package python-Markdown.43069
Index: Markdown-3.5.2/markdown/__main__.py
===================================================================
--- Markdown-3.5.2.orig/markdown/__main__.py
+++ Markdown-3.5.2/markdown/__main__.py
@@ -21,7 +21,6 @@ from __future__ import annotations
import sys
import optparse
-import codecs
import warnings
import markdown
try:
@@ -100,7 +99,7 @@ def parse_options(args=None, values=None
extension_configs = {}
if options.configfile:
- with codecs.open(
+ with open(
options.configfile, mode="r", encoding=options.encoding
) as fp:
try:
Index: Markdown-3.5.2/markdown/core.py
===================================================================
--- Markdown-3.5.2.orig/markdown/core.py
+++ Markdown-3.5.2/markdown/core.py
@@ -417,7 +417,7 @@ class Markdown:
# Read the source
if input:
if isinstance(input, str):
- input_file = codecs.open(input, mode="r", encoding=encoding)
+ input_file = open(input, mode="r", encoding=encoding)
else:
input_file = codecs.getreader(encoding)(input)
text = input_file.read()
Index: Markdown-3.5.2/markdown/extensions/md_in_html.py
===================================================================
--- Markdown-3.5.2.orig/markdown/extensions/md_in_html.py
+++ Markdown-3.5.2/markdown/extensions/md_in_html.py
@@ -234,7 +234,11 @@ class HTMLExtractorExtra(HTMLExtractor):
if self.rawdata[i:i+3] == '<![' and not self.rawdata[i:i+9] == '<![CDATA[':
# We have encountered the bug in #1534 (Python bug `gh-77057`).
# Provide an override until we drop support for Python < 3.13.
- return self.parse_bogus_comment(i)
+ result = self.parse_bogus_comment(i)
+ if result == -1:
+ self.handle_data(self.rawdata[i:i + 1])
+ return i + 1
+ return result
# The same override exists in `HTMLExtractor` without the check
# for `mdstack`. Therefore, use parent of `HTMLExtractor` instead.
return super(HTMLExtractor, self).parse_html_declaration(i)
Index: Markdown-3.5.2/markdown/htmlparser.py
===================================================================
--- Markdown-3.5.2.orig/markdown/htmlparser.py
+++ Markdown-3.5.2/markdown/htmlparser.py
@@ -89,6 +89,8 @@ class HTMLExtractor(htmlparser.HTMLParse
self.lineno_start_cache = [0]
+ self.override_comment_update = False
+
# This calls self.reset
super().__init__(*args, **kwargs)
self.md = md
@@ -249,8 +251,21 @@ class HTMLExtractor(htmlparser.HTMLParse
self.handle_empty_tag('&{};'.format(name), is_block=False)
def handle_comment(self, data: str):
+ # Check if the comment is unclosed, if so, we need to override position
+ i = self.line_offset + self.offset + len(data) + 4
+ if self.rawdata[i:i + 3] != '-->':
+ self.handle_data('<')
+ self.override_comment_update = True
+ return
self.handle_empty_tag('<!--{}-->'.format(data), is_block=True)
+ def updatepos(self, i: int, j: int) -> int:
+ if self.override_comment_update:
+ self.override_comment_update = False
+ i = 0
+ j = 1
+ return super().updatepos(i, j)
+
def handle_decl(self, data: str):
self.handle_empty_tag('<!{}>'.format(data), is_block=True)
@@ -274,7 +289,11 @@ class HTMLExtractor(htmlparser.HTMLParse
if self.rawdata[i:i+3] == '<![' and not self.rawdata[i:i+9] == '<![CDATA[':
# We have encountered the bug in #1534 (Python bug `gh-77057`).
# Provide an override until we drop support for Python < 3.13.
- return self.parse_bogus_comment(i)
+ result = self.parse_bogus_comment(i)
+ if result == -1:
+ self.handle_data(self.rawdata[i:i + 1])
+ return i + 1
+ return result
return super().parse_html_declaration(i)
# This is not the beginning of a raw block so treat as plain data
# and avoid consuming any tags which may follow (see #1066).
@@ -304,7 +323,8 @@ class HTMLExtractor(htmlparser.HTMLParse
self.__starttag_text = None
endpos = self.check_for_whole_start_tag(i)
if endpos < 0:
- return endpos
+ self.handle_data(self.rawdata[i:i + 1])
+ return i + 1
rawdata = self.rawdata
self.__starttag_text = rawdata[i:endpos]
diff --git a/markdown/htmlparser.py b/markdown/htmlparser.py
index 478e70216..63e5df31b 100644
--- a/markdown/htmlparser.py
+++ b/markdown/htmlparser.py
@@ -69,6 +69,20 @@
)?
\s* # trailing whitespace
""", re.VERBOSE)
+htmlparser.locatetagend = re.compile(r"""
+ [a-zA-Z][^`\t\n\r\f />]* # tag name
+ [\t\n\r\f /]* # optional whitespace before attribute name
+ (?:(?<=['"\t\n\r\f /])[^`\t\n\r\f />][^\t\n\r\f /=>]* # attribute name
+ (?:= # value indicator
+ (?:'[^']*' # LITA-enclosed value
+ |"[^"]*" # LIT-enclosed value
+ |(?!['"])[^>\t\n\r\f ]* # bare value
+ )
+ )?
+ [\t\n\r\f /]* # possibly followed by a space
+ )*
+ >?
+""", re.VERBOSE)
# Match a blank line at the start of a block of text (two newlines).
# The newlines may be preceded by additional whitespace.