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:
parent
7c32804575
commit
a696392560
2 changed files with 6 additions and 5 deletions
10
todo/Todo.py
10
todo/Todo.py
|
@ -66,7 +66,7 @@ class Todo(TodoObject):
|
||||||
TodoObject: The object found.
|
TodoObject: The object found.
|
||||||
"""
|
"""
|
||||||
if level > 0:
|
if level > 0:
|
||||||
for child in object.children:
|
for child in object.children[::-1]:
|
||||||
if child.level < level:
|
if child.level < level:
|
||||||
return child
|
return child
|
||||||
return object
|
return object
|
||||||
|
@ -135,20 +135,20 @@ class Todo(TodoObject):
|
||||||
else:
|
else:
|
||||||
self._parse_note(line, self.children[-1])
|
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.
|
"""Gets the markdown text of the current data loaded into the object.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
category_spacing (int, optional): Amount of newlines between categories. Defaults to 1.
|
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:
|
Returns:
|
||||||
str: the markdown text generated
|
str: the markdown text generated
|
||||||
"""
|
"""
|
||||||
output = ""
|
output = ""
|
||||||
for i in self.get_children(immediate=True):
|
for i in self.get_children():
|
||||||
if isinstance(i, Category):
|
if isinstance(i, Category):
|
||||||
|
if i.level > 0:
|
||||||
|
output += "\n"*category_spacing
|
||||||
output += f"{i}\n"
|
output += f"{i}\n"
|
||||||
elif isinstance(i, Task):
|
elif isinstance(i, Task):
|
||||||
output += f"{i.level*2*' '}{i}\n"
|
output += f"{i.level*2*' '}{i}\n"
|
||||||
|
|
|
@ -23,6 +23,7 @@ class TodoObject:
|
||||||
output.append(child)
|
output.append(child)
|
||||||
elif not immediate:
|
elif not immediate:
|
||||||
output.append(child)
|
output.append(child)
|
||||||
|
return output
|
||||||
|
|
||||||
def set_parents(self, parent):
|
def set_parents(self, parent):
|
||||||
parent: TodoObject
|
parent: TodoObject
|
||||||
|
|
Loading…
Reference in a new issue