worklist.extend(reversed(el.contents))
elif el.name in ["ul", "ol", "table", "thead", "tbody"]:
worklist.extend(reversed(el.contents))
- elif el.name in ["li", "p", "div", "h1", "h2", "blockquote"]:
+ elif el.name in ["li", "p", "div", "blockquote"] or re.match(r"h[1-6]$", el.name):
worklist.append(NEW_LINE)
worklist.extend(reversed(el.contents))
worklist.append(NEW_LINE)
worklist.append(SPACE)
worklist.append(NEW_LINE)
else:
- raise RuntimeError(f"can't parse tag {el.tag}")
+ raise RuntimeError(f"can't parse tag {el.name}")
tmp_lines = (
"".join(" " if part is SPACE else part for part in parts).strip()