AI turns documents or topics into real, native PowerPoint decks—with native shapes, transitions and animations, data-backed charts and tables on demand, audio narration from speaker notes, and support for your own .pptx templates. · by Hugo He
fix(source-to-md): keep Typst text when pandoc cannot evaluate it
hugohe3176235a3d6fa
diff --git a/skills/ppt-master/scripts/docs/conversion.md b/skills/ppt-master/scripts/docs/conversion.mdindex 039715e8..6daf4fb7 100644--- a/skills/ppt-master/scripts/docs/conversion.md+++ b/skills/ppt-master/scripts/docs/conversion.md@@ -128,6 +128,10 @@ Native path (no external binary required):Pandoc fallback (only if you need these):- `.doc`, `.odt`, `.rtf`, `.tex`/`.latex`, `.rst`, `.org`, `.typ`+- `.typ` evaluates under pandoc, so a real project file that imports its template,+ a package, or a custom function fails there; it then (or without pandoc) keeps the+ source text with `=` headings mapped to Markdown and raw blocks, markup, math, and+ code calls verbatim, recorded as a conversion-profile warning.```bashpython3 scripts/source_to_md/doc_to_md.py lecture.docxdiff --git a/skills/ppt-master/scripts/source_to_md/doc_to_md.py b/skills/ppt-master/scripts/source_to_md/doc_to_md.pyindex 5bde375d..a0a6f7b1 100644--- a/skills/ppt-master/scripts/source_to_md/doc_to_md.py+++ b/skills/ppt-master/scripts/source_to_md/doc_to_md.py@@ -11,6 +11,8 @@ Primary formats (pure Python, no external tools required):Fallback formats (require pandoc installed):.doc .odt .rtf .tex .latex .rst .org .typ+ (.typ keeps its text with headings mapped when pandoc is absent or cannot+ evaluate a file that imports a template, package, or custom function)All paths produce the same output convention:<input>.md Markdown file@@ -1528,6 +1530,52 @@ def _convert_with_pandoc(input_file: Path, out_file: Path, suffix: str) -> str:return markdown+_TYPST_HEADING_RE = re.compile(r"^(=+)\s+(.*)$")+_TYPST_FENCE_RE = re.compile(r"`{3,}")+++def _typst_text_to_markdown(source: str) -> str:+ """Map Typst headings to Markdown and keep everything else as written.++ Pandoc's Typst reader evaluates the document, so a real project file that+ imports its template, a package, or a custom function fails as a whole.+ This pass evaluates nothing: headings become ``#`` headings, while raw+ blocks (opened anywhere on a line, as in ``#code(```typ``), markup, and+ code calls stay verbatim.+ """+ lines = []+ fence: str | None = None+ for line in source.splitlines():+ heading = _TYPST_HEADING_RE.match(line) if fence is None else None+ for run in _TYPST_FENCE_RE.findall(line):+ if fence is None:+ fence = run+ elif run == fence:+ fence = None+ lines.append(f"{'#' * len(heading.group(1))} {heading.group(2)}" if heading else line)+ return "\n".join(lines) + "\n"+++def _convert_typst(input_file: Path, out_file: Path, warnings: list[str]) -> str:+ """Convert through pandoc, falling back to the non-evaluating text pass."""+ if _check_pandoc():+ markdown = _convert_with_pandoc(input_file, out_file, ".typ")+ if markdown:+ return markdown+ reason = "pandoc could not evaluate the Typst source (imports, packages, or custom functions)"+ else:+ reason = "pandoc is not installed"+ print(f"[INFO] {reason}; keeping the Typst text with headings mapped")+ warnings.append(+ f"{reason}: kept the source text with headings mapped to Markdown; "+ "code calls, show/set rules, and math stay as written Typst"+ )+ markdown = _typst_text_to_markdown(input_file.read_text(encoding="utf-8"))+ out_file.write_text(markdown, encoding="utf-8")+ _report_result(out_file, None)+ return markdown++# ─────────────────────────────────────────────────────────────# Dispatcher# ─────────────────────────────────────────────────────────────@@ -1585,13 +1633,18 @@ def convert_to_markdown(input_path: str, output_path: str | None = None) -> str:_, format_desc = PANDOC_FORMATS[suffix]print(f"[INFO] Converting {format_desc} via pandoc: {input_file.name}")- markdown = _convert_with_pandoc(input_file, out_file, suffix)+ warnings = []+ if suffix == ".typ":+ markdown = _convert_typst(input_file, out_file, warnings)+ else:+ markdown = _convert_with_pandoc(input_file, out_file, suffix)if markdown:profile_path = write_conversion_profile_best_effort(input_path=str(input_file),markdown_path=out_file,converter="doc_to_md.py",conversion_type=suffix.lstrip("."),+ warnings=warnings,)if profile_path:print(f" Wrote conversion profile -> {profile_path}")diff --git a/skills/ppt-master/scripts/tests/test_source_to_md_cli.py b/skills/ppt-master/scripts/tests/test_source_to_md_cli.pyindex 4ad0d9ac..ee4924c3 100644--- a/skills/ppt-master/scripts/tests/test_source_to_md_cli.py+++ b/skills/ppt-master/scripts/tests/test_source_to_md_cli.py@@ -410,5 +410,32 @@ class SourceCollisionTests(unittest.TestCase):self.assertFalse(source.with_suffix(".conversion_profile.json").exists())+class TypstFallbackTests(unittest.TestCase):+ def test_project_file_with_imports_keeps_text_and_maps_headings(self) -> None:+ from doc_to_md import convert_to_markdown++ with tempfile.TemporaryDirectory() as tmp:+ source = Path(tmp) / "chapter.typ"+ source.write_text(+ '#import "mod.typ": *\n'+ "#show: book.page.with(title: [Intro])\n\n"+ "= Headings\n\n"+ "Write *markup* here.\n\n"+ "#code(```typ\n= Not a heading\n```)\n\n"+ "== Next\n",+ encoding="utf-8",+ )+ with redirect_stdout(io.StringIO()):+ markdown = convert_to_markdown(str(source))++ lines = markdown.splitlines()+ self.assertIn("# Headings", lines)+ self.assertIn("## Next", lines)+ self.assertIn("= Not a heading", lines)+ self.assertIn("Write *markup* here.", lines)+ profile = json.loads(source.with_suffix(".conversion_profile.json").read_text(encoding="utf-8"))+ self.assertTrue(any("headings mapped" in warning for warning in profile["warnings"]))++if __name__ == "__main__":unittest.main()