Add \t support to parsing.

This commit is contained in:
riley 2021-09-25 20:16:08 -04:00
parent a696392560
commit e768dae978
1 changed files with 4 additions and 1 deletions

View File

@ -15,13 +15,15 @@ logger = logging.getLogger("Todo")
logger.addHandler(logging.StreamHandler())
class Todo(TodoObject):
def __init__(self, data_file : Path = Path.home().joinpath("todo.md")):
def __init__(self, data_file : Path = Path.home().joinpath("todo.md"), tab_spacing = 2):
"""Todo class, reads and parses a todo.md from a file. Default file is 'todo.md' in the home directory.
Args:
data_file (Path, optional): Location of the markdown file to load from. Defaults to ~/todo.md.
tab_spacing (int, optional): How many levels a tab character should represent. Defaults to 2.
"""
self.data_file = data_file
self.tab_spacing = tab_spacing
super().__init__(-1, "File")
self._load_data()
@ -125,6 +127,7 @@ class Todo(TodoObject):
"""Load categories and tasks from self.data_file."""
with self.data_file.open("r") as f:
for line in f:
line = line.replace("\t", self.tab_spacing*" ")
line = line.rstrip()
if len(line.strip()) == 0: # skip empty lines
continue