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.
process_element/process_tagrecurse three Python frames per nesting level (markdownify/__init__.py228-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.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_tagand past amax_depthoption fall back tonode.get_text(); a full fix walksnode.descendantswithout recursion.