matthewwithanm / matthewwithanm/python-markdownify
RecursionError on deeply nested HTML (about 330 levels), separate from the cyclic-tree case in #256
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 2.2k
- Forks
- 203
- PR merge metrics
- No merged PRs in 30d
Description
process_element / process_tag recurse three Python frames per nesting level (markdownify/__init__.py 228-232, 234, 287-288 on develop), so a plain acyclic tree hits the default recursion limit at around 330 levels. Real mail clients produce this: Outlook wraps quoted replies in empty <div>s and a long thread easily passes that depth.
deep div nesting depth=300: OK len=5
deep div nesting depth=330: RecursionError (maximum recursion depth exceeded)
deep div nesting depth=500: RecursionError (maximum recursion depth exceeded)
cyclic soup (p contains its ancestor div): RecursionError (maximum recursion depth exceeded)
Repro on 1.2.3: https://gist.github.com/HardMax71/bbfc6f70bab3ec6417d4f80324f40387. The one-liner is markdownify("<div>" * 330 + "x" + "</div>" * 330).
I applied the hunk from #274 to 1.2.3 to check: the cyclic case passes, the depth case still fails. So #256/#274 cover cycles and this needs its own guard. Cheapest fix: thread a depth counter through process_tag and past a max_depth option fall back to node.get_text(); a full fix walks node.descendants without recursion.
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in markdownify/init.py around process_element and process_tag at lines 228-232, 234, and 287-288, then run the 330-level nesting reproducer from the issue. Compare the depth failure with the cyclic-tree handling from #256/#274. Done means deeply nested acyclic HTML no longer raises RecursionError while the existing cyclic case remains covered.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Active
- Clarity
- Mostly clear
- Newbie friendliness
- 68/100