diff options
Diffstat (limited to '.ai/scripts')
| -rwxr-xr-x | .ai/scripts/drill-to-anki.py | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/.ai/scripts/drill-to-anki.py b/.ai/scripts/drill-to-anki.py index 50e1afd..543ccd8 100755 --- a/.ai/scripts/drill-to-anki.py +++ b/.ai/scripts/drill-to-anki.py @@ -100,6 +100,32 @@ def title_from_org(org_text: str) -> str | None: return None +def strip_org_metadata(body_lines: list[str]) -> list[str]: + """Drop :PROPERTIES: drawers and SCHEDULED/DEADLINE/CLOSED planning lines. + + Org-drill needs these in the source file (SRS state lives in the + PROPERTIES drawer; SCHEDULED carries the next-review date), but they + are noise on the back of an Anki card. + """ + cleaned: list[str] = [] + in_drawer = False + planning_re = re.compile(r"^\s*(SCHEDULED|DEADLINE|CLOSED):\s") + drawer_start_re = re.compile(r"^\s*:PROPERTIES:\s*$") + drawer_end_re = re.compile(r"^\s*:END:\s*$") + for line in body_lines: + if in_drawer: + if drawer_end_re.match(line): + in_drawer = False + continue + if drawer_start_re.match(line): + in_drawer = True + continue + if planning_re.match(line): + continue + cleaned.append(line) + return cleaned + + def parse(org_text: str) -> list[tuple[str, str, str]]: """Return [(front, back_html, tag), ...] for every :drill: card.""" cards: list[tuple[str, str, str]] = [] @@ -130,6 +156,7 @@ def parse(org_text: str) -> list[tuple[str, str, str]]: break body_lines.append(nxt) i += 1 + body_lines = strip_org_metadata(body_lines) while body_lines and not body_lines[0].strip(): body_lines.pop(0) while body_lines and not body_lines[-1].strip(): |
