How vishal7090/md-generator works
1. This repository is a multi-format document conversion platform packaged as a single Python distribution, mdengine, with the import namespace md_generator. Its core purpose is to turn different source document types into Markdown plus related artifacts such as extracted images, tables, manifests, and ZIP bundles.
2. The architecture is organized by input format, not by delivery channel. The main format subsystems live under src/md_generator/ as separate packages for pdf, word, ppt, xlsx, image, text, and archive. Each subsystem has its own converter logic, option model, and often its own API layer, while sharing the same top-level packaging and runtime.
3. There are three primary execution surfaces over the same conversion engines:
- CLI entry points like md-pdf, md-word, md-ppt, etc.
- FastAPI HTTP services under each format’s api package.
- MCP servers, either embedded in the HTTP app or run as standalone processes.
The CLI, API, and MCP layers are thin wrappers around the same in-process conversion functions.
4. The shared data flow is consistent across formats: input file or upload enters a format-specific front door, passes through parsing/extraction logic, then a markdown emitter or artifact writer produces output files. For larger conversions, the output is often not just a .md file but an artifact directory or ZIP bundle containing the Markdown plus extracted assets and metadata.
5. The PDF pipeline is centered on extraction and emission. pdf/pdf_extract.py and pdf/md_emit.py suggest a two-stage flow: parse PDF content, then render Markdown. The API path supports sync and async conversion jobs, with downloadable results, which implies heavier jobs can be offloaded and retrieved later.
6. The Word subsystem is more document-structure oriented. It exposes converter logic, per-request job handling for API usage, artifact management, and a dedicated settings.py. The README and file layout indicate DOCX conversion produces Markdown and may also expose extracted images or related assets. There is also a smaller api/convert_util.py used to bridge API-facing requests to the conversion core.
7. The PowerPoint subsystem has the richest artifact model. It includes embedded media extraction, OOXML media handling, post-processing of extracted assets, and vendorized converters borrowed for PDF and Word-style Markdown conversion inside slides. This points to a pipeline that converts slide content, extracts tables/images/media, and then organizes them into a structured artifact directory.
8. Excel conversion is built differently from the document converters. It has a dedicated converter_core.py, excel_reader.py, markdown_emitter.py, and convert_config.py, suggesting a more tabular, sheet-oriented pipeline. The output can be Markdown and CSV-related artifacts, with the API package named app.py rather than main.py, but it follows the same service pattern.
9. The image subsystem is OCR-centric and backend-pluggable. It includes multiple OCR backends (easyocr, paddle, tesseract) behind a common backend interface, along with I/O utilities and emit.py. This subsystem is designed to support different OCR engines depending on installed extras and runtime options, which is a key architectural boundary.
10. The text subsystem handles plain text, JSON, and XML as structured text sources. Its split emitters (md_emit_txt.py, md_emit_json.py, md_emit_xml.py) and format detection module indicate that the conversion path first identifies the input type and then renders it using a format-specific Markdown strategy.
11. The archive subsystem is a recursive orchestration layer. ZIP inputs are unpacked, inspected, and then dispatched to the appropriate converter for nested office documents, PDFs, images, or text files. This is why the README emphasizes installing corresponding extras when archives contain nested formats: the archive engine is a coordinator over the other subsystems rather than a standalone extractor.
12. The API layer is standardized but per-format configurable. Each service uses its own environment-variable prefix for limits, temp directories, and CORS settings, and most expose POST /convert/sync, async job creation, job status, and result download endpoints. This implies a common request lifecycle with a format-specific settings boundary.
13. MCP support is a parallel integration channel for agentic clients. Some formats mount MCP on the same FastAPI server at /mcp, while others provide standalone MCP server modules. This is architecturally separate from the conversion core but uses the same underlying converter functions.
14. The repository is intentionally split between src/md_generator/ and legacy *-to-md/ folders. The src tree is the real library and runtime source, while the sibling folders mostly hold tests, fixtures, thin converter.py shims, and some helper launch scripts. That separation matters for diagrams: conversion logic lives in src, while the legacy folders are integration and compatibility surfaces.
15. Dependency boundaries are enforced through extras in pyproject.toml and the per-format requirements*.txt files. Heavy dependencies such as OCR engines, FastAPI, or MCP libraries are optional and only needed for the corresponding subsystem. This keeps the base package lightweight and makes format support composable rather than monolithic.
16. For an architecture diagram, the key nodes are: source document/file input, format-specific CLI/API/MCP entry points, the conversion core per format, asset extraction/emission components, and output targets such as Markdown files, artifact directories, ZIP bundles, or async job downloads. The main cross-cutting concern is that all front ends converge on the same in-process converters, while each format owns its own parsing, extraction, and output conventions.
Main entry points: convert_impl.py Archive core · __init__.py md_generator · pdf/converter.py PDF core · ppt/converter.py PPT core
Components 27
src/md_generator
Primary library and runtime source tree
- md_generator · Top-level library namespace for all converters
src/md_generator/__init__.py - Outputs · Markdown files, extracted assets, ZIP bundles, and job downloads
- PDF API · HTTP front door for PDF conversion and job retrieval
src/md_generator/pdf/api/main.py - PDF core · Coordinates PDF extraction and Markdown emission
src/md_generator/pdf/converter.py - PDF extract · Parses PDF content and prepares structured extraction data
src/md_generator/pdf/pdf_extract.py - PDF emit · Renders extracted PDF content into Markdown output
src/md_generator/pdf/md_emit.py - Word API · HTTP front door for DOCX conversion and job handling
src/md_generator/word/api/main.py - Word core · Document-structure converter for Word inputs
src/md_generator/word/converter.py - Word artifact · Builds Markdown plus extracted assets and related package output
src/md_generator/word/artifact.py - PPT API · HTTP front door for slide conversion and jobs
src/md_generator/ppt/api/main.py - PPT core · Coordinates slide parsing, extraction, and artifact assembly
src/md_generator/ppt/converter.py - PPT extract · Extracts embedded media and OOXML-backed slide assets
src/md_generator/ppt/embedded_extract.py - PPT post · Normalizes extracted media, tables, and bundled assets
src/md_generator/ppt/post_assets.py - XLSX API · HTTP front door for spreadsheet conversion
src/md_generator/xlsx/api/app.py - XLSX core · Sheet-oriented conversion engine
src/md_generator/xlsx/converter_core.py - XLSX read · Loads workbook and sheet data for conversion
src/md_generator/xlsx/excel_reader.py - XLSX emit · Produces Markdown and CSV-oriented output
src/md_generator/xlsx/markdown_emitter.py - Image API · HTTP front door for OCR-based image conversion
src/md_generator/image/api/main.py - Image core · Coordinates OCR backend selection and emission
src/md_generator/image/converter.py - OCR backends · Pluggable OCR engines behind a shared interface
src/md_generator/image/backends/base.py - Image emit · Writes Markdown and artifact outputs for image OCR results
src/md_generator/image/emit.py - Text API · HTTP front door for plain text, JSON, and XML conversion
src/md_generator/text/api/main.py - Text detect · Detects structured text input type before rendering
src/md_generator/text/format_detect.py - Text emitters · Format-specific Markdown emitters for text, JSON, and XML
src/md_generator/text/md_emit_txt.py - Archive API · HTTP front door for recursive archive conversion
src/md_generator/archive/api/main.py - Archive core · Unpacks ZIP inputs and dispatches nested files to the right converter
src/md_generator/archive/convert_impl.py
Legacy wrappers
Compatibility folders and thin entrypoints around the shared source tree
- Legacy CLIs · Thin repo-root converter shims and launch scripts for format-specific entrypoints
Connections 44
- md_generator → PDF API: contains · Top-level package exposes PDF runtime
- md_generator → Word API: contains · Top-level package exposes Word runtime
- md_generator → PPT API: contains · Top-level package exposes PowerPoint runtime
- md_generator → XLSX API: contains · Top-level package exposes spreadsheet runtime
- md_generator → Image API: contains · Top-level package exposes image OCR runtime
- md_generator → Text API: contains · Top-level package exposes structured text runtime
- md_generator → Archive API: contains · Top-level package exposes archive runtime
- Legacy CLIs → PDF core: wraps · Repo-root shims invoke the shared converters
- Legacy CLIs → Word core: wraps · Repo-root shims invoke the shared converters
- Legacy CLIs → PPT core: wraps · Repo-root shims invoke the shared converters
- Legacy CLIs → XLSX core: wraps · Repo-root shims invoke the shared converters
- Legacy CLIs → Image core: wraps · Repo-root shims invoke the shared converters
- Legacy CLIs → Text detect: wraps · Repo-root shims invoke the shared converters
- Legacy CLIs → Archive core: wraps · Repo-root shims invoke the shared converters
- PDF API → PDF core: dispatches · HTTP layer delegates to in-process conversion
- PDF core → PDF extract: parses · Conversion begins with PDF extraction
- PDF core → PDF emit: renders · Extracted PDF data is turned into Markdown
- PDF core → Outputs: writes · May produce Markdown plus bundled artifacts
- Word API → Word core: dispatches · HTTP layer delegates to in-process conversion
- Word core → Word artifact: assembles · Word conversion builds artifact bundles
- Word artifact → Outputs: writes · DOCX output becomes Markdown and extracted assets
- PPT API → PPT core: dispatches · HTTP layer delegates to in-process conversion
- PPT core → PPT extract: extracts · Slides are parsed for embedded media and content
- PPT core → PPT post: postprocesses · Extracted assets are normalized and organized
- PPT core → Outputs: writes · Produces Markdown plus artifact directory or ZIP bundle
- XLSX API → XLSX core: dispatches · HTTP layer delegates to in-process conversion
- XLSX core → XLSX read: reads · Workbook data is loaded before rendering
- XLSX core → XLSX emit: renders · Sheet data is emitted as Markdown or CSV-related output
- XLSX core → Outputs: writes · Spreadsheet conversion can produce files and logs
- Image API → Image core: dispatches · HTTP layer delegates to in-process conversion
- Image core → OCR backends: selects · OCR backend is chosen by runtime options and extras
- Image core → Image emit: renders · OCR results are emitted to Markdown and assets
- Image emit → Outputs: writes · Image OCR output may include extracted artifacts
- Text API → Text detect: dispatches · HTTP layer delegates to format detection and conversion
- Text detect → Text emitters: routes · Input type determines which Markdown emitter is used
- Text emitters → Outputs: writes · Text, JSON, and XML render to Markdown output
- Archive API → Archive core: dispatches · HTTP layer delegates to recursive archive orchestration
- Archive core → PDF core: dispatches · Nested PDFs are sent to the PDF pipeline
- Archive core → Word core: dispatches · Nested Word files are sent to the Word pipeline
- Archive core → PPT core: dispatches · Nested presentations are sent to the PPT pipeline
- Archive core → XLSX core: dispatches · Nested spreadsheets are sent to the XLSX pipeline
- Archive core → Image core: dispatches · Nested images are sent to the OCR pipeline
- Archive core → Text detect: dispatches · Nested text-like files are sent to the text pipeline
- Archive core → Outputs: writes · Archive conversion coordinates final Markdown and bundles