diff --git a/org_rw/org_rw.py b/org_rw/org_rw.py index 90ff004..c40f0e4 100644 --- a/org_rw/org_rw.py +++ b/org_rw/org_rw.py @@ -464,8 +464,9 @@ class Headline: if isinstance(c, dom.ListItem) ] - if ((len(list_children) > 0) - and (len(list_children[-1].orig.indentation) + if (len(list_children) == 0): + break + if ((len(list_children[-1].orig.indentation) <= len(line.indentation))): # No more breaking out of lists, it's indentation # is less than ours diff --git a/tests/11-nested-lists.org b/tests/11-nested-lists.org new file mode 100644 index 0000000..a4a8632 --- /dev/null +++ b/tests/11-nested-lists.org @@ -0,0 +1,16 @@ +#+TITLE: 11-Nested lists +#+DESCRIPTION: Simple org file to test nested lists +#+TODO: TODO(t) PAUSED(p) | DONE(d) + +* Nested lists + :PROPERTIES: + :ID: 11-nested-lists + :CREATED: [2020-01-01 Wed 01:01] + :END: + - 1 + - 1.1 + - 1.2 + - 2 + - 2.1 + - 2.2 + - 3 diff --git a/tests/test_org.py b/tests/test_org.py index 1255067..2f4200d 100644 --- a/tests/test_org.py +++ b/tests/test_org.py @@ -724,6 +724,39 @@ class TestSerde(unittest.TestCase): self.assertTrue(len(non_props) == 1, 'Expected , with only (1) element') + def test_nested_lists_html_file_11(self): + with open(os.path.join(DIR, "11-nested-lists.org")) as f: + doc = load(f) + + hl = doc.getTopHeadlines()[0] + + tree = hl.as_dom() + non_props = [ + item + for item in tree + if not isinstance(item, dom.PropertyDrawerNode) + ] + print_tree(non_props) + self.assertTrue((len(non_props) == 1) and (isinstance(non_props[0], dom.ListGroupNode)), + 'Expected only as top level') + + dom_list = non_props[0] + children = dom_list.children + self.assertTrue(len(children) == 5, 'Expected 5 items inside , 3 texts and 2 sublists') + + # Assert texts + self.assertEqual(children[0].content, ['1']) + self.assertEqual(children[2].content, ['2']) + self.assertEqual(children[4].content[0], '3') # Might be ['3', '\n'] but shouldn't be a breaking change + + # Assert lists + self.assertTrue(isinstance(children[1], dom.ListGroupNode), 'Expected sublist inside "1"') + self.assertEqual(children[1].children[0].content, ['1.1']) + self.assertEqual(children[1].children[1].content, ['1.2']) + self.assertTrue(isinstance(children[3], dom.ListGroupNode), 'Expected sublist inside "2"') + self.assertEqual(children[3].children[0].content, ['2.1']) + self.assertEqual(children[3].children[1].content, ['2.2']) + def print_tree(tree, indentation=0, headline=None): for element in tree: