75_SECTIONS: tuple[tuple[str, str, str], ...] = (
97 """Return ``{note_id: (title, verbatim_body)}`` for the 3 deferred sections."""
98 text = todo_text.replace(
"\r\n",
"\n")
99 out: dict[str, tuple[str, str]] = {}
100 for prefix, note_id, title
in _SECTIONS:
101 match = re.search(rf
"^{re.escape(prefix)}.*$", text, re.MULTILINE)
104 nxt = _BOUNDARY_RE.search(text, match.end())
105 end = nxt.start()
if nxt
else len(text)
106 body = text[match.start():end].strip(
"\n")
107 out[note_id] = (title, _TRAILING_RULE_RE.sub(
"", body).strip(
"\n"))
111def backfill(todo_md: Path, source_dir: Path) -> TodoReport:
112 """Write each deferred section to ``source/notes/<id>.md`` (verbatim body)."""
114 sections =
parse_sections(Path(todo_md).read_text(encoding=
"utf-8"))
115 out_dir = Path(source_dir) /
"notes"
116 out_dir.mkdir(parents=
True, exist_ok=
True)
118 for note_id, (title, body)
in sections.items():
119 model = rc.Note(schema_version=rc.SCHEMA_VERSION, id=note_id, title=title)
120 (out_dir / f
"{note_id}.md").write_text(
121 format_record_text(model, body=body), encoding=
"utf-8", newline=
""
123 report.notes_written += 1
124 report.sections[note_id] = (title, body)
125 _dbg(
"OC_CHAT.MAIN", func, f
"wrote note {note_id} ({len(body)} chars)", 3)
126 _dbg(
"OC_CHAT.MAIN", func, f
"wrote {report.notes_written} TODO-narrative notes", 2)