Fix Logseq Task List query block pattern #1

Merged
d_mcknight merged 11 commits from feat/logseq-query-cleanup-fix into main 2026-11-03 20:21:28 -08:00
Showing only changes of commit c6bed839e8 - Show all commits

View file

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