Fix: Catch query blocks with no prefix #2

Merged
d_mcknight merged 4 commits from bugfix/catch-all-query-formats into main 2026-11-05 19:37:13 -08:00
Showing only changes of commit 53547303a8 - Show all commits

View file

@ -12,15 +12,12 @@ from typing import Tuple
def remove_task_list_queries(content: str) -> Tuple[str, int]:
"""
Remove all Task List query blocks from Logseq content.
Handles multiple formats:
1. - query-table:: + collapsed:: (no dash) + #+BEGIN_QUERY
2. collapsed:: (no dash) + - query-table:: + #+BEGIN_QUERY
3. - collapsed:: + #+BEGIN_QUERY
4. - #+BEGIN_QUERY (direct with dash)
5. #+BEGIN_QUERY (no dash, no prefix - just whitespace)
Simple approach: match from #+BEGIN_QUERY to #+END_QUERY if it contains Task/ToDo List title.
This catches all formats regardless of prefix lines.
"""
# Pattern handles all 5 formats above
pattern = r'(?:- query-table::\s*(?:true|false)\s*\n\s+collapsed::\s*true\s*\n\s*#\+BEGIN_QUERY|collapsed::\s*true\s*\n\s*- query-table::\s*(?:true|false)\s*\n\s*#\+BEGIN_QUERY|- collapsed::\s*true\s*\n\s*#\+BEGIN_QUERY|- #\+BEGIN_QUERY|\s*#\+BEGIN_QUERY)[\s\S]*?:title\s*"[✅✓]?\s*(?:Task|ToDo)\s*List"[\s\S]*?#\+END_QUERY'
# Simple pattern: match #+BEGIN_QUERY ... #+END_QUERY blocks that contain Task/ToDo List title
# This catches all formats without needing to enumerate all possible prefixes
pattern = r'#+BEGIN_QUERY[\s\S]*?:title\s*"[✅✓]?\s*(?:Task|ToDo)\s*List"[\s\S]*?#\+END_QUERY'
matches = re.findall(pattern, content)
count = len(matches)