subcheck parsing
This commit is contained in:
parent
e1f979f146
commit
b0f81d7f86
@ -11,14 +11,14 @@ now = datetime.datetime.now()
|
|||||||
|
|
||||||
ALL_TODO_RE = re.compile(
|
ALL_TODO_RE = re.compile(
|
||||||
r"""^
|
r"""^
|
||||||
(?:\s*[-*]\s*)?
|
(?:\s*-\s*)?
|
||||||
(TODO|IDEA|DONE):? # label starts a line
|
(TODO|IDEA|DONE):? # label starts a line
|
||||||
\s*([^\{\n]+) # body ends at { or newline
|
\s*([^\{\n]+) # body ends at { or newline
|
||||||
(?:\s*(\{.*\}))? # repeated variations of {...} tags
|
(?:\s*(\{.*\}))? # repeated variations of {...} tags
|
||||||
""",
|
""",
|
||||||
re.MULTILINE | re.VERBOSE,
|
re.VERBOSE,
|
||||||
)
|
)
|
||||||
|
CHECKBOX_RE = re.compile(r"\s*-\s*\[([ x]?)\]\s*(.*)")
|
||||||
TAG_SPLIT_RE = re.compile(r"\{([^:]+):([^}]+)\}")
|
TAG_SPLIT_RE = re.compile(r"\{([^:]+):([^}]+)\}")
|
||||||
TODO_TODO_RE = re.compile(r"^(TODO):?\s*")
|
TODO_TODO_RE = re.compile(r"^(TODO):?\s*")
|
||||||
|
|
||||||
@ -43,26 +43,47 @@ def scan_contents(file: pathlib.Path) -> dict:
|
|||||||
|
|
||||||
|
|
||||||
def pull_todos(file: pathlib.Path):
|
def pull_todos(file: pathlib.Path):
|
||||||
text = file.read_text()
|
text = file.read_text().splitlines()
|
||||||
todos = ALL_TODO_RE.findall(text)
|
active_todo = None
|
||||||
for todo in todos:
|
for line in text:
|
||||||
tag_strs = []
|
todo = ALL_TODO_RE.match(line)
|
||||||
style = ""
|
if todo:
|
||||||
status, description, tags = todo
|
if active_todo:
|
||||||
for tag, val in TAG_SPLIT_RE.findall(tags):
|
yield active_todo
|
||||||
ts, style = parse_todo_tag(tag, val)
|
tag_strs = []
|
||||||
tag_strs.append(ts)
|
style = ""
|
||||||
if status == "DONE":
|
status, description, tags = todo.groups()
|
||||||
style = "#999999"
|
if tags:
|
||||||
elif status == "IDEA":
|
for tag, val in TAG_SPLIT_RE.findall(tags):
|
||||||
style = "blue"
|
ts, style = parse_todo_tag(tag, val)
|
||||||
yield {
|
tag_strs.append(ts)
|
||||||
"file": file.name,
|
if status == "DONE":
|
||||||
"status": status,
|
style = "#999999"
|
||||||
"description": description,
|
elif status == "IDEA":
|
||||||
"tags": " | ".join(tag_strs),
|
style = "blue"
|
||||||
"style": style,
|
active_todo = {
|
||||||
}
|
"file": file.name,
|
||||||
|
"status": status,
|
||||||
|
"description": description,
|
||||||
|
"tags": " | ".join(tag_strs),
|
||||||
|
"style": style,
|
||||||
|
"subtasks": [],
|
||||||
|
}
|
||||||
|
elif active_todo:
|
||||||
|
# check for checkbox if we're nested inside a todo
|
||||||
|
checkbox = CHECKBOX_RE.match(line)
|
||||||
|
if checkbox:
|
||||||
|
checkbox_status, desc = checkbox.groups()
|
||||||
|
active_todo["subtasks"].append(
|
||||||
|
{"status": checkbox_status, "description": desc}
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
yield active_todo
|
||||||
|
active_todo = None
|
||||||
|
|
||||||
|
# make sure to yield final line if needed
|
||||||
|
if active_todo:
|
||||||
|
yield active_todo
|
||||||
|
|
||||||
|
|
||||||
def human_readable_date(dt: datetime.datetime) -> str:
|
def human_readable_date(dt: datetime.datetime) -> str:
|
||||||
|
Loading…
Reference in New Issue
Block a user