Fix pattern to handle ToDo List and multi-line query blocks

This commit is contained in:
Hermes Agent 2026-11-03 16:56:48 -08:00
parent a607d2871b
commit c6bed839e8

View file

@ -8,7 +8,7 @@ Most days have two such blocks:
2. Personal Task List (non-work tasks)
The query blocks are marked with #+BEGIN_QUERY ... #+END_QUERY and contain
"title "✅ Task List"" in their configuration.
"title "✅ Task List"" or "title "✅ ToDo List"" in their configuration.
"""
import re
@ -28,13 +28,11 @@ def remove_task_list_queries(content: str) -> Tuple[str, int]:
Tuple of (cleaned content, number of blocks removed)
"""
# Pattern to match query-table lines and #+BEGIN_QUERY ... #+END_QUERY blocks
# that contain Task List. The query blocks in Logseq may have:
# that contain Task List or ToDo List. Handles:
# - query-table:: true/false
# - Optional query-sort-by:: and query-sort-desc:: lines (lines starting with
# whitespace and containing "query-" prefix)
# - #+BEGIN_QUERY ... #+END_QUERY
# Note: # must be escaped as \# in regex
pattern = r'query-table:: (?:true|false)(?:\s*\n\s+query-.*?:: .*?)*\s*\n\s*\#\+BEGIN_QUERY.*?:title "✅ Task List".*?\#\+END_QUERY'
# - Optional collapsed::, query-sort-* lines
# - Multi-line or single-line #+BEGIN_QUERY ... #+END_QUERY
pattern = r'query-table::\s*(?:true|false).*?#\+BEGIN_QUERY.*?:title\s*"[✅✓]?\s*(?:Task|ToDo)\s*List".*?#\+END_QUERY'
# Find all matches first to count them
matches = re.findall(pattern, content, re.DOTALL)
@ -112,7 +110,7 @@ def main():
dry_run = args.dry_run
# Collect files to process
files: List[Path] = []
files = []
if target.is_file():
if target.suffix.lower() not in ['.md', '.markdown']:
@ -151,4 +149,4 @@ def main():
if __name__ == '__main__':
main()
main()