From 31455f075eb5b9c53bf1d77c7bc42b2cb8dd1c3d Mon Sep 17 00:00:00 2001 From: Matt Wiseley Date: Sat, 18 Oct 2025 10:38:43 -0400 Subject: [PATCH] HTML output tweaks --- export_todoist.py | 6 +++ requirements.txt | 1 + todoist_backup_template.html | 92 ++++++++++++++++++++++++++++++++---- 3 files changed, 91 insertions(+), 8 deletions(-) diff --git a/export_todoist.py b/export_todoist.py index 4d45a62..1d39e7e 100644 --- a/export_todoist.py +++ b/export_todoist.py @@ -162,6 +162,12 @@ def main(): loader=FileSystemLoader(os.path.dirname(__file__)), autoescape=select_autoescape(['html', 'xml']) ) + # Add markdown filter + try: + import markdown + env.filters['markdown'] = lambda text: markdown.markdown(text or "") + except ImportError: + env.filters['markdown'] = lambda text: text or "" template = env.get_template("todoist_backup_template.html") html_filename = f"Todoist-Actual-Backup-{today}.html" with open(html_filename, "w", encoding="utf-8") as f: diff --git a/requirements.txt b/requirements.txt index 402d659..0e2d2a3 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1,4 @@ todoist-api-python Jinja2 requests +markdown diff --git a/todoist_backup_template.html b/todoist_backup_template.html index b9be47a..a89eeaf 100644 --- a/todoist_backup_template.html +++ b/todoist_backup_template.html @@ -13,7 +13,8 @@ .completed { color: #888; } .attachments { margin: 0.5em 0 0.5em 1em; } .comments { margin: 0.5em 0 0.5em 1em; font-size: 0.95em; color: #444; } - .field { font-weight: bold; } + .task-name { font-weight: bold; } + .field-label { font-style: italic; } a.attachment-link { color: #2d72d9; text-decoration: underline; } .meta { color: #666; font-size: 0.95em; } @@ -40,11 +41,42 @@
{% for task in project.tasks %}
- Content: {{ task.content }}
- ID: {{ task.id }} | Due: {{ task.due }} | Priority: {{ task.priority }}
+ {{ task.content | markdown | safe }}
+ {% if task.description %} +
{{ task.description | markdown | safe }}
+ {% endif %} + + {% set meta_fields = [] %} + {% if task.id is not none %} + {% set _ = meta_fields.append('ID: ' ~ task.id) %} + {% endif %} + {% if task.due and task.due.date %} + {% set due_dt = task.due.date %} + {% if due_dt.__class__.__name__ == 'datetime' or due_dt.__class__.__name__ == 'date' %} + {% set due_fmt = due_dt.strftime('%Y-%m-%d') %} + {% else %} + {% set due_str = due_dt|string %} + {% if 'T' in due_str %} + {% set due_fmt = due_str[:10] %} + {% else %} + {% set due_fmt = due_str %} + {% endif %} + {% endif %} + {% set _ = meta_fields.append('Due: ' ~ due_fmt) %} + {% endif %} + {% if task.due and task.due.is_recurring %} + {% if task.due.string %} + {% set _ = meta_fields.append('Recurring: ' ~ task.due.string) %} + {% endif %} + {% endif %} + {% if task.priority is not none %} + {% set _ = meta_fields.append('Priority: ' ~ task.priority) %} + {% endif %} + {{ meta_fields|join(' | ') }} +
{% if task.attachments %}
- Attachments: + Attachments:
    {% for att in task.attachments %}
  • {{ att.file_name or att.local_file }}
  • @@ -54,7 +86,7 @@ {% endif %} {% if task.comments %}
    - Comments: + Comments:
      {% for comment in task.comments %}
    • {{ comment.content }} ({{ comment.posted_at }})
    • @@ -69,11 +101,55 @@
      {% for task in project.completed_tasks %}
      - Content: {{ task.content }}
      - ID: {{ task.id }} | Due: {{ task.due }} | Priority: {{ task.priority }}
      + {{ task.content | markdown | safe }}
      + {% if task.description %} +
      {{ task.description | markdown | safe }}
      + {% endif %} + + {% set meta_fields = [] %} + {% if task.id is not none %} + {% set _ = meta_fields.append('ID: ' ~ task.id) %} + {% endif %} + {% if task.due and task.due.date %} + {% set due_dt = task.due.date %} + {% if due_dt.__class__.__name__ == 'datetime' or due_dt.__class__.__name__ == 'date' %} + {% set due_fmt = due_dt.strftime('%Y-%m-%d %H:%M') if due_dt.__class__.__name__ == 'datetime' else due_dt.strftime('%Y-%m-%d 00:00') %} + {% else %} + {% set due_str = due_dt|string %} + {% if 'T' in due_str %} + {% set due_fmt = due_str[:16].replace('T', ' ') %} + {% else %} + {% set due_fmt = due_str %} + {% endif %} + {% endif %} + {% set _ = meta_fields.append('Due: ' ~ due_fmt) %} + {% endif %} + {% if task.due and task.due.is_recurring %} + {% if task.due.string %} + {% set _ = meta_fields.append('Recurring: ' ~ task.due.string) %} + {% endif %} + {% endif %} + {% if task.priority is not none %} + {% set _ = meta_fields.append('Priority: ' ~ task.priority) %} + {% endif %} + {% if task.completed_at %} + {% if task.completed_at.__class__.__name__ == 'datetime' or task.completed_at.__class__.__name__ == 'date' %} + {% set completed_fmt = task.completed_at.strftime('%Y-%m-%d') %} + {% else %} + {% set completed_str = task.completed_at|string %} + {% if 'T' in completed_str %} + {% set completed_fmt = completed_str[:10] %} + {% else %} + {% set completed_fmt = completed_str %} + {% endif %} + {% endif %} + {% set _ = meta_fields.append('Completed: ' ~ completed_fmt) %} + {% endif %} + {{ meta_fields|join(' | ') }} +
      {% if task.attachments %}
      - Attachments: + Attachments: