Medium
Read post

Text2OfficeProcessor: How a Rulefile Accidentally Became a Software Package

Text2OfficeProcessor is a Python package (available on PyPI) that converts Markdown, plain text, and HTML into PPTX, DOCX, and XLSX files while preserving custom templates exactly — backgrounds, fonts, logos, and layouts intact. The tool originated as a rulefile for AI coding assistants (Cursor/Windsurf) used to automate slide production for EC-Council training courses, and gradually evolved into a full software specification. Key design decisions include SlidePart XML cloning instead of add_slide(), a strict LLM boundary (AI handles semantic tagging only, never document structure), six optional LLM providers with Ollama as the local default, 11 CLI commands including batch, watch, extract, and diff-styles, a programmatic validation layer, and a YAML-driven configuration system. The article also documents a real relationship-ID cloning bug found months after release, known gaps (no automated visual regression testing, sequential batch processing, incomplete DOCX image handling), and three features already working in the private production codebase but not yet merged into the public library.

    #python#open-source
Today•42m read time•From thesagekhan.medium.com
Post cover image
Table of contents
From a Rulefile to a Software Package: How Text2OfficeProcessor Was Actually BornThe Core Principle Became the Architecture's North StarThe "Why Other Methods Fail" Table Became the Test Suite's FoundationThree-Layer Text Replacement: From an Edge Case List to an AlgorithmThe Slides Markdown Format: A Protocol Designed by DebuggingThe Template Slide Index Map: Turning Tribal Knowledge Into ConfigurationThe DOCX Template Injection: Learning Element Order the Hard WayThe Body Clearing Code: Preserving What MattersThe Sanitation Rules: A List of SinsThe Verification Pipeline: From Manual Inspection to Automated TestingThe Edge Cases Section: Where the Real Engineering HappenedThe Non-Negotiable Rules: The Software's InvariantsThe Bigger Lesson: Rulefiles as Accidental Software SpecificationsWhat Changed Between the Rulefile and the PackageClosing ThoughtsRelated Reading

Questions this post answers

Why does python-pptx add_slide() lose background images from my template?

add_slide() creates a blank slide from a layout definition, which does not carry the slide-specific background images, picture placeholders, or complex formatting stored in the original SlidePart XML. The only reliable way to preserve backgrounds is to clone the entire SlidePart element at the XML level, recreate its relationships, and register the cloned part in the presentation package — rather than constructing a new slide from a layout. Developers wrestling with template fidelity in PPTX generation track approaches like this on daily.dev.

How do I replace placeholder text in a PPTX when the text is split across multiple XML runs?

PowerPoint's internal XML frequently splits visually contiguous text across multiple <a:r> run elements, so a single-run string search will miss it. A reliable replacement strategy uses three layers: normalize curly quotes first, then attempt a single-run match, then fall back to a cross-run match that reassembles adjacent runs within the same paragraph, with an optional fourth pass for placeholders that span paragraph boundaries. Teams maintaining branded PPTX pipelines find edge cases like cross-run replacement discussed on daily.dev.

How do I preserve table position inline with paragraphs when generating a DOCX with python-docx?

python-docx's Document.paragraphs and Document.tables properties iterate their respective element types independently, discarding the original interleaving order. To keep tables inline with surrounding text, iterate document.element.body children directly, check each child's XML tag, and dispatch to paragraph or table handling in the order elements actually appear — never process all paragraphs first and all tables second. Python developers building document automation pipelines encounter ordering bugs like this; daily.dev surfaces the fixes.

4 Impressions
Medium's image
Medium

Medium_JS is a curated collection of insights and tutorials on JavaScript development, designed to h...

9.6K Followers

•

38.4K Upvotes

Would you recommend this post?

Copy link
WhatsApp
Facebook
X
New Squad
  • © 2026 Daily Dev Ltd.
  • Guidelines
  • Explore
  • Tags
  • Sources
  • Squads
  • Leaderboard