Fix query block pattern to handle both formats with/without query-table line; add batch processing script

This commit is contained in:
Hermes Agent 2026-11-03 19:28:18 -08:00
parent c6bed839e8
commit e8527ded34
2 changed files with 120 additions and 9 deletions

17
clean_task_lists.py Normal file → Executable file
View file

@ -27,19 +27,18 @@ def remove_task_list_queries(content: str) -> Tuple[str, int]:
Returns:
Tuple of (cleaned content, number of blocks removed)
"""
# Pattern to match query-table lines and #+BEGIN_QUERY ... #+END_QUERY blocks
# that contain Task List or ToDo List. Handles:
# - query-table:: true/false
# - 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'
# Pattern to match Task List query blocks. Handles two formats:
# 1. With query-table:: line: "- query-table:: true" + "collapsed:: true" + "#+BEGIN_QUERY"
# 2. Without query-table:: line: "- collapsed:: true" + "#+BEGIN_QUERY"
# Both formats end with "#+END_QUERY" and contain :title "✅ Task List" or :title "✅ ToDo List"
pattern = r'(?:- query-table::\s*(?:true|false)\s*\n\s+collapsed::\s*true\s*\n\s*#\+BEGIN_QUERY[\s\S]*?:title\s*"[✅✓]?\s*(?:Task|ToDo)\s*List"[\s\S]*?#\+END_QUERY|- collapsed::\s*true\s*\n\s*#\+BEGIN_QUERY[\s\S]*?:title\s*"[✅✓]?\s*(?:Task|ToDo)\s*List"[\s\S]*?#\+END_QUERY)'
# Find all matches first to count them
matches = re.findall(pattern, content, re.DOTALL)
matches = re.findall(pattern, content)
count = len(matches)
# Remove all Task List query blocks
cleaned = re.sub(pattern, '', content, flags=re.DOTALL)
cleaned = re.sub(pattern, '', content)
return cleaned, count
@ -149,4 +148,4 @@ def main():
if __name__ == '__main__':
main()
main()