From a69639256010f44cfc6354ab178c4963753c782b Mon Sep 17 00:00:00 2001 From: riley Date: Sat, 25 Sep 2021 19:47:55 -0400 Subject: [PATCH] Fix get_md() and parent assignments. - now properly outputs category spacing in get_md() - removed task_spacing and note_spacing, may return later. - fixed parent assignment, now iterates through the reversed children list. - this finds the closest parent. - TodoObject now properly returns output with get_children() --- todo/Todo.py | 10 +++++----- todo/TodoObject.py | 1 + 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/todo/Todo.py b/todo/Todo.py index 6f6af30..f4239f8 100644 --- a/todo/Todo.py +++ b/todo/Todo.py @@ -66,7 +66,7 @@ class Todo(TodoObject): TodoObject: The object found. """ if level > 0: - for child in object.children: + for child in object.children[::-1]: if child.level < level: return child return object @@ -135,20 +135,20 @@ class Todo(TodoObject): else: self._parse_note(line, self.children[-1]) - def get_md(self, category_spacing: int = 1, task_spacing: int = 0, note_spacing: int = 0) -> str: + def get_md(self, category_spacing: int = 1) -> str: """Gets the markdown text of the current data loaded into the object. Args: category_spacing (int, optional): Amount of newlines between categories. Defaults to 1. - task_spacing (int, optional): Amount of newlines between tasks. Defaults to 0. - note_spacing (int, optional): Amount of newlines between category notes. Defaults to 0. Returns: str: the markdown text generated """ output = "" - for i in self.get_children(immediate=True): + for i in self.get_children(): if isinstance(i, Category): + if i.level > 0: + output += "\n"*category_spacing output += f"{i}\n" elif isinstance(i, Task): output += f"{i.level*2*' '}{i}\n" diff --git a/todo/TodoObject.py b/todo/TodoObject.py index 4dbab1d..b541067 100644 --- a/todo/TodoObject.py +++ b/todo/TodoObject.py @@ -23,6 +23,7 @@ class TodoObject: output.append(child) elif not immediate: output.append(child) + return output def set_parents(self, parent): parent: TodoObject