From: facelessuser <faceless.shop@gmail.com>
Date: Mon, 21 Jul 2025 08:56:43 -0600
Subject: Fix failing cases for Python 3.13.6 and 3.14

New change requires us to monkey patch `locatetagend` to prevent
capturing incomplete tags in code spans.

(cherry picked from commit 23c301de28e12426408656efdfa153b11d4ff558)
---
 markdown/htmlparser.py | 14 ++++++++++++++
 1 file changed, 14 insertions(+)

diff --git a/markdown/htmlparser.py b/markdown/htmlparser.py
index 478e702..63e5df3 100644
--- a/markdown/htmlparser.py
+++ b/markdown/htmlparser.py
@@ -69,6 +69,20 @@ htmlparser.locatestarttagend_tolerant = re.compile(r"""
    )?
   \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.
