aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorQuentin Carbonneaux2020-05-08 19:12:50 +0200
committerQuentin Carbonneaux2020-05-08 19:12:50 +0200
commit71d0315f2559dca43a5ea733f91199965b8b7879 (patch)
tree34d7e99453337beab0d2894b15abf8fd23ff2cab
parent24497500d30a6719b2eb92c3795ab067e2cdf14f (diff)
Recursively look for the first string node
-rw-r--r--doc/tools/coqrst/coqdoc/main.py16
1 files changed, 11 insertions, 5 deletions
diff --git a/doc/tools/coqrst/coqdoc/main.py b/doc/tools/coqrst/coqdoc/main.py
index 9a12d5e6f8..de0d912c03 100644
--- a/doc/tools/coqrst/coqdoc/main.py
+++ b/doc/tools/coqrst/coqdoc/main.py
@@ -48,16 +48,22 @@ def coqdoc(coq_code, coqdoc_bin=None):
finally:
os.remove(filename)
+def first_string_node(node):
+ """Return the first string node, or None if does not exist"""
+ while node.children:
+ node = next(node.children)
+ if isinstance(node, NavigableString):
+ return node
+
def lex(source):
"""Convert source into a stream of (css_classes, token_string)."""
coqdoc_output = coqdoc(source)
soup = BeautifulSoup(coqdoc_output, "html.parser")
root = soup.find(class_='code')
- if root.children:
- # strip the leading '\n'
- first = next(root.children)
- if isinstance(first, NavigableString) and first.string[0] == '\n':
- first.string.replace_with(first.string[1:])
+ # strip the leading '\n'
+ first = first_string_node(root)
+ if first and first.string[0] == '\n':
+ first.string.replace_with(first.string[1:])
for elem in root.children:
if isinstance(elem, NavigableString):
yield [], elem