From 46a2c387ebadf63721ad864290ff1fe21ace5f1a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sergio=20Mart=C3=ADnez=20Portela?= Date: Thu, 26 Nov 2020 23:39:35 +0100 Subject: [PATCH] Avoid adding an empty line when headline has none. --- org_dom/org_dom.py | 6 +++++- tests/01-simple-2.org | 10 ++++------ 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/org_dom/org_dom.py b/org_dom/org_dom.py index 36b905b..8993eba 100644 --- a/org_dom/org_dom.py +++ b/org_dom/org_dom.py @@ -515,6 +515,9 @@ def tokenize_contents(contents: str): def parse_contents(raw_contents: List[RawLine]): + if len(raw_contents) == 0: + return [] + contents_buff = [] for line in raw_contents: contents_buff.append(line.line) @@ -695,7 +698,8 @@ class OrgDom: last_type = ltype structured_lines.append(content) - yield "".join(structured_lines) + if len(structured_lines) > 0: + yield "".join(structured_lines) for child in headline.children: yield from self.dump_headline(child) diff --git a/tests/01-simple-2.org b/tests/01-simple-2.org index 42da1c2..291632a 100644 --- a/tests/01-simple-2.org +++ b/tests/01-simple-2.org @@ -11,12 +11,10 @@ First level content ** Second level - :PROPERTIES: - :ID: 01-simple-second-level-id - :END: - - Second level content with no indentation - +:PROPERTIES: +:ID: 01-simple-second-level-id +:END: +Second level content with no indentation or space around *** Third level with no content **** Forth level :PROPERTIES: