From 70081245091cb7316ebfe973dfd561de739a3d67 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sergio=20Mart=C3=ADnez=20Portela?= Date: Thu, 13 Apr 2023 23:56:58 +0200 Subject: [PATCH] Use more robust list de-indentation handler. --- org_rw/org_rw.py | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/org_rw/org_rw.py b/org_rw/org_rw.py index e3534a8..822367b 100644 --- a/org_rw/org_rw.py +++ b/org_rw/org_rw.py @@ -457,17 +457,20 @@ class Headline: current_node = sublist indentation_tree.append(current_node) - while len(indentation_tree) > 0 and ( - (len(indentation_tree[-1].children) > 0) - and len( - [ - c - for c in indentation_tree[-1].children - if isinstance(c, dom.ListItem) - ][-1].orig.indentation - ) - > len(line.indentation) - ): + while len(indentation_tree) > 0: + list_children = [ + c + for c in indentation_tree[-1].children + if isinstance(c, dom.ListItem) + ] + + if ((len(list_children) > 0) + and (len(list_children[-1].orig.indentation) + <= len(line.indentation))): + # No more breaking out of lists, it's indentation + # is less than ours + break + rem = indentation_tree.pop(-1) if len(indentation_tree) == 0: indentation_tree.append(rem)