$ show datalab-to/marker
Marker is a high-accuracy document-to-markdown converter that transforms PDFs, images, DOCX, PPTX, XLSX, HTML, and EPUB files into clean markdown, JSON, HTML, or chunked output. It uses a pipeline architecture: a Provider extracts raw text and layout from the input, Builders (layout, line, OCR) construct a structured document model, Processors apply domain-specific transformations (table reconstruction, equation extraction, footnote handling, LLM-based correction), and Renderers produce the final output format. The system is driven by the Surya VLM for layout analysis and OCR, with an optional LLM enhancement layer (Gemini, Claude, OpenAI, etc.) for complex tasks like table merging, inline math, and image descriptions. Key entry points include CLI tools (`marker`, `marker_single`), a FastAPI server (`marker_server`), a Streamlit GUI, and a Python API (`PdfConverter`, `TableConverter`, `OCRConverter`). External dependencies include surya-ocr, pdftext, pypdfium2, torch, transformers, and various LLM SDKs. The codebase is well-structured with a clear separation of concerns, extensive test coverage, and a benchmark suite (olmocr-bench) that validates quality scores (~76% overall balanced mode).
The LLM identified 4 files worth highlighting for reuse:
A self-contained pydantic model for polygon/bbox operations (expand, rescale, merge, intersection, overlap, gap computation) with cached properties. This is the foundational geometry primitive used throughout the pipeline and can be extracted into any project requiring spatial operations on document layouts.
A custom markdown renderer built on markdownify that handles complex table structures (rowspan/colspan), math delimiters, chemical fences, hyphenation, and pagination markers. The table-to-markdown grid algorithm is non-trivial and reusable for any document-to-markdown pipeline.
A deterministic, CPU-only table reconstruction algorithm that uses pdftext data (garble detection, header-band splitting, whitespace-gap projection, composite scoring) to produce HTML tables without any LLM or GPU dependency. Cleanly separated and adaptable to other PDF text extraction backends.
Defines the BaseService abstract interface for LLM providers (Gemini, Claude, OpenAI, Ollama, etc.) with a standardized __call__ signature accepting prompt, image, block, and response_schema. This pattern allows easy addition of new LLM backends and is reusable in any application that needs pluggable AI services.