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()
This commit is contained in:
riley 2021-09-25 19:47:55 -04:00
parent 7c32804575
commit a696392560
2 changed files with 6 additions and 5 deletions

View file

@ -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"

View file

@ -23,6 +23,7 @@ class TodoObject:
output.append(child)
elif not immediate:
output.append(child)
return output
def set_parents(self, parent):
parent: TodoObject