md2star.preprocessing package
Submodules
- md2star.preprocessing.alt_text module
- md2star.preprocessing.images module
- md2star.preprocessing.language module
- md2star.preprocessing.lint module
- md2star.preprocessing.math module
- md2star.preprocessing.mermaid module
- md2star.preprocessing.pipeline module
- md2star.preprocessing.regexes module
- md2star.preprocessing.tables module
Module contents
md2star Markdown preprocessor package.
The orchestrator preprocess_markdown() runs a fixed sequence of phases
on a raw Markdown string before it reaches Pandoc. Each phase lives in its
own submodule so the pipeline is easy to test, extend, or swap.
Public API
preprocess_markdown()— the orchestrator (only thing wrappers call)render_mermaid_local()— re-exported for tests/mocksPHASES— canonical phase-name set (for--skip-phase)
- md2star.preprocessing.fill_empty_alt_text(content, base_dir='.', model=None)[source]
Replace
empty-alt images with an LLM-generated description.Mirrors
md2star.preprocessing.lint.lint_with_llm()’s safety net: if Ollama is missing, the daemon is unreachable, the vision model is not pulled (and cannot be pulled), or the request fails, the original content is returned unchanged. The pass is never load-bearing.
- md2star.preprocessing.is_ollama_installed()[source]
True iff the
ollamabinary is reachable onPATH.Used as the auto-enable gate for lint: if the user does not have Ollama installed at all, we stay completely silent. If they do, we take care of starting the daemon and pulling the model on demand — the rationale being “the tool is here, so use it without asking”.
- Return type:
- md2star.preprocessing.isolate_images_for_pptx(content)[source]
Push standalone images and pipe-tables onto fresh PPTX slides.
Pandoc’s PPTX writer maps each
## H2(or# H1) heading to one slide. A slide that mixes prose with an image silently drops the image, and a slide that mixes prose with a table cramps everything together. Inserting a blank##before the offending block forces it onto its own slide. Empty headings render as nothing in DOCX, so the rewrite is harmless for that output.Both images and tables are isolated by the same pass — keeping them in one function avoids cascading
##insertions from two independent walkers tripping over each other’s output.
- md2star.preprocessing.preprocess_markdown(content, base_dir='.', inject_metadata=True, lint_enabled=False, skip_phases=None, *, allow_remote_images=False, offline=False)[source]
Run the full preprocessing pipeline on a Markdown string.
- Parameters:
content (str) – Raw Markdown source.
base_dir (str) – Directory used to resolve relative image paths and to receive downloaded remote images / mermaid renders.
inject_metadata (bool) – Whether to inject
lang/date_formatbased on language detection (default: True). Equivalent to skippinglanguage.lint_enabled (bool) – Whether to run the optional Ollama LLM lint (default: False). Opt-in because it requires Ollama, adds latency, and can in rare cases rewrite content despite the safety guard.
skip_phases (Iterable[str], optional) – Phase names to skip (see
PHASES). Merged with anymd2star_skip:list found in the document’s YAML front-matter.allow_remote_images (bool, keyword-only) – Whether to download
references. Defaults toFalse(the safe-by-default policy introduced in v1.2.0): remote image markers are left in place, and the user sees a warning if any were skipped. PassTrueto opt in.offline (bool, keyword-only) – Hard-disable every network-touching phase. Takes precedence over
allow_remote_imagesandlint_enabled.
- Return type: