Lectii text: extract_text_lessons.py + Modul 3 #9 sumarizata
extract_audio.py sarea peste lectiile fara video. Gasita una in curriculum-ul accesibil (Modul 3 #9 - expirari de optiuni, witching, 0DTE), cu 4847 de caractere de continut real. Era numarata gresit ca acoperita. Plus: - render_html.py: index grupat pe module cu titlul H1 al fiecarei pagini - render_html.py: garda pe liniile goale din <svg> (rup blocul HTML tacut) Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01MtSTyTmt6AbCL9j5ajEDm1
This commit is contained in:
@@ -5,6 +5,7 @@ Also (re)writes summaries/index.html linking every rendered page.
|
||||
Run after adding/editing any summary.
|
||||
"""
|
||||
|
||||
import re
|
||||
from pathlib import Path
|
||||
|
||||
import markdown
|
||||
@@ -36,22 +37,44 @@ PAGE_TEMPLATE = """<!DOCTYPE html>
|
||||
"""
|
||||
|
||||
|
||||
def render_file(md_path: Path) -> Path:
|
||||
def check_svgs(md_path: Path, text: str) -> None:
|
||||
"""O linie goală în interiorul unui <svg> face python-markdown să rupă
|
||||
blocul HTML în paragrafe, iar browserul aruncă restul elementelor —
|
||||
diagrama se randează pe jumătate, fără nicio eroare. S-a întâmplat deja
|
||||
de două ori; mai bine crapă aici decât să publici o diagramă stricată."""
|
||||
for m in re.finditer(r"<svg .*?</svg>", text, re.S):
|
||||
if re.search(r"\n[ \t]*\n", m.group(0)):
|
||||
line = text[: m.start()].count("\n") + 1
|
||||
raise SystemExit(f"{md_path}:{line}: linie goală în interiorul <svg> — markdown va rupe blocul")
|
||||
|
||||
|
||||
def render_file(md_path: Path) -> tuple[Path, str]:
|
||||
text = md_path.read_text(encoding="utf-8")
|
||||
check_svgs(md_path, text)
|
||||
body = markdown.markdown(text, extensions=["extra", "toc"])
|
||||
title = text.splitlines()[0].lstrip("# ").strip() if text else md_path.stem
|
||||
html_path = md_path.with_suffix(".html")
|
||||
html_path.write_text(PAGE_TEMPLATE.format(title=title, body=body), encoding="utf-8")
|
||||
return html_path
|
||||
return html_path, title
|
||||
|
||||
|
||||
def write_index(pages: list[Path]):
|
||||
items = "\n".join(
|
||||
f'<li><a href="{p.relative_to(ROOT)}">{p.parent.name} / {p.stem}</a></li>'
|
||||
for p in sorted(pages)
|
||||
)
|
||||
def write_index(pages: list[tuple[Path, str]]):
|
||||
"""Grupat pe module, cu titlul H1 al fiecărei pagini — numele fișierului
|
||||
(o dată, un număr) nu spune nimic despre ce e înăuntru."""
|
||||
sections = []
|
||||
current = None
|
||||
for path, title in sorted(pages):
|
||||
if path.parent.name != current:
|
||||
if current is not None:
|
||||
sections.append("</ul>")
|
||||
current = path.parent.name
|
||||
sections.append(f"<h2>{current.replace('_', ' ')}</h2><ul>")
|
||||
sections.append(f'<li><a href="{path.relative_to(ROOT)}">{title}</a></li>')
|
||||
if current is not None:
|
||||
sections.append("</ul>")
|
||||
(ROOT / "index.html").write_text(
|
||||
PAGE_TEMPLATE.format(title="ATM — Sumarizări", body=f"<h1>ATM — Sumarizări</h1><ul>{items}</ul>"),
|
||||
PAGE_TEMPLATE.format(title="ATM — Sumarizări",
|
||||
body="<h1>ATM — Sumarizări</h1>" + "".join(sections)),
|
||||
encoding="utf-8",
|
||||
)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user