subcheck parsing
This commit is contained in:
		
							parent
							
								
									e1f979f146
								
							
						
					
					
						commit
						b0f81d7f86
					
				
					 1 changed files with 44 additions and 23 deletions
				
			
		|  | @ -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,12 +43,17 @@ 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: | ||||||
|  |         todo = ALL_TODO_RE.match(line) | ||||||
|  |         if todo: | ||||||
|  |             if active_todo: | ||||||
|  |                 yield active_todo | ||||||
|             tag_strs = [] |             tag_strs = [] | ||||||
|             style = "" |             style = "" | ||||||
|         status, description, tags = todo |             status, description, tags = todo.groups() | ||||||
|  |             if tags: | ||||||
|                 for tag, val in TAG_SPLIT_RE.findall(tags): |                 for tag, val in TAG_SPLIT_RE.findall(tags): | ||||||
|                     ts, style = parse_todo_tag(tag, val) |                     ts, style = parse_todo_tag(tag, val) | ||||||
|                     tag_strs.append(ts) |                     tag_strs.append(ts) | ||||||
|  | @ -56,13 +61,29 @@ def pull_todos(file: pathlib.Path): | ||||||
|                 style = "#999999" |                 style = "#999999" | ||||||
|             elif status == "IDEA": |             elif status == "IDEA": | ||||||
|                 style = "blue" |                 style = "blue" | ||||||
|         yield { |             active_todo = { | ||||||
|                 "file": file.name, |                 "file": file.name, | ||||||
|                 "status": status, |                 "status": status, | ||||||
|                 "description": description, |                 "description": description, | ||||||
|                 "tags": " | ".join(tag_strs), |                 "tags": " | ".join(tag_strs), | ||||||
|                 "style": style, |                 "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 a new issue