From 5e4a9f8ff2df3deac85b6fd4d08cadf4be6361e3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sergio=20Mart=C3=ADnez=20Portela?= Date: Mon, 31 Oct 2022 21:50:18 +0100 Subject: [PATCH] Fix parsing of lists inside drawers. --- org_rw/org_rw.py | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/org_rw/org_rw.py b/org_rw/org_rw.py index 01cae02..c3d9f57 100644 --- a/org_rw/org_rw.py +++ b/org_rw/org_rw.py @@ -489,15 +489,26 @@ class Headline: elif content.strip().upper() == ":END:": if current_node is None: logging.warning('Finished node (:END:) with no known starter') - elif not (isinstance( - current_node, dom.PropertyDrawerNode - ) or isinstance( - current_node, dom.LogbookDrawerNode - ) or isinstance( - current_node, dom.ResultsDrawerNode - )): - raise Exception('Unexpected node: {}'.format(current_node)) - current_node = None + else: + tree_up = list(tree) + while len(tree_up) > 0: + node = tree_up[-1] + if (isinstance( + node, dom.PropertyDrawerNode + ) or isinstance( + node, dom.LogbookDrawerNode + ) or isinstance( + node, dom.ResultsDrawerNode + )): + tree = tree_up + current_node = node + break + else: + tree_up.pop(-1) + else: + raise Exception('Unexpected node ({}) on headline (id={}), line {}'.format(current_node, self.id, linenum)) + current_node = None + tree.pop() elif content.strip().upper() == ":RESULTS:": assert current_node is None current_node = dom.ResultsDrawerNode()