Add \t support to parsing.

This commit is contained in:
riley 2021-09-25 20:16:08 -04:00
parent a696392560
commit e768dae978

View file

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