Description: Fix coqdoc lexer leaking BeautifulSoup nodes into the doctree
 The coqdoc lexer yielded BeautifulSoup string nodes (NavigableString),
 which keep a reference to their parent HTML parse tree.  Sphinx stores
 the yielded tokens in the doctree, so pickling the doctree (Sphinx's
 doctree cache) dragged in the whole parse tree and recurse far too
 deeply, failing with RecursionError on Python 3.12.  Yield plain str
 tokens instead.
Author: tangxiaofeng <tangxiaofeng@kylinos.cn>
Forwarded: not-needed
Last-Update: 2026-09-14

--- coq-doc-8.20.0.orig/doc/tools/coqrst/coqdoc/main.py
+++ coq-doc-8.20.0/doc/tools/coqrst/coqdoc/main.py
@@ -66,11 +66,15 @@ def lex(source):
         first.string.replace_with(first.string[1:])
     for elem in root.children:
         if isinstance(elem, NavigableString):
-            yield [], elem
+            # Yield a plain str: BeautifulSoup string nodes keep a reference to
+            # their parent tree, which would otherwise drag the whole parse
+            # tree into the doctree and make pickling it (Sphinx's doctree
+            # cache) recurse far too deeply.
+            yield [], str(elem)
         elif elem.name == "span":
             if elem.string:
                 cls = "coqdoc-{}".format(elem.get("title", "comment"))
-                yield [cls], elem.string
+                yield [cls], str(elem.string)
             else:
                 # handle multi-line comments
                 children = list(elem.children)
@@ -78,7 +82,7 @@ def lex(source):
                 for elem2 in children:
                     if isinstance(elem2, NavigableString):
                         cls = ["coqdoc-comment"] if mlc else []
-                        yield cls, elem2
+                        yield cls, str(elem2)
                     elif elem2.name == 'br':
                         pass
         elif elem.name == 'br':
