A Open WebUI Tool that generates
native Word (.docx) documents from Markdown (with YAML frontmatter) or a JSON
spec produced by the model. It doesn't export HTML or PDF: it builds the document
directly with python-docx, with a coherent design system — cover pages, numbered
headings with rules, styled tables, callouts, code blocks, signatures, TOC and a
running header/footer.
The resulting file is saved through Open WebUI's Files API (with a /cache/files
fallback) and a clickable download link appears in the chat.
License: MIT · Author: IANUSTEC
Document generated from the example examples/report.md → examples/demo_report.docx.
- Native, editable .docx (text, tables and styles are editable in Word / Pages / LibreOffice).
- Dual input, auto-detected: Markdown-with-frontmatter (preferred) or JSON — same output.
- 7 templates with a coherent palette derived from a single
accentcolor:report,whitepaper,proposal,letter,memo,minutes,blank. - Cover pages:
band(accent panel),rule(editorial) orplain. - Numbered headings (1, 1.1, 1.1.1) with H1/H2 accent rules — auto-strips any manual number.
- Rich tables: filled accent header, zebra rows, automatic right-alignment of numeric/currency columns.
- Callouts:
info,success,warning,danger(colored bar + tint). - Lists (bullets, ordered, checklists), blockquotes, code blocks, signatures, TOC, page breaks.
==highlight==maps to accent-colored emphasis; smart quotes; typographic spacing.- Header / footer with 3 zones (
left/center/right) and live page numbers ({{page}}/{{pages}}). - Human-readable filename derived from the title (e.g.
Q3 Board Report.docx). - Optional images from Unsplash (with a key) or generated via Open WebUI.
- Single-file: one self-contained
.py, ready to paste into the Tools registry.
- Open WebUI
>= 0.4.0 - Python:
python-docx,Pillow,markdown-it-py,mdit-py-plugins,PyYAML,lxml(declared in the frontmatter → Open WebUI installs them automatically) - Optional:
httpx(fetch images from URL / Unsplash)
- Open the tool page on the Open WebUI community site.
- Click Get / Import to your instance.
- In your Open WebUI instance go to Workspace → Tools → +.
- Paste the contents of
generate_documents.py. - Save. The declared dependencies are installed on first use.
- Enable the tool for the model (or chat) that should use it.
The model calls generate_document(content), where content is either
Markdown-with-frontmatter (preferred) or a JSON string.
---
template: report
title: "Digital Transformation Program — FY 2026"
subtitle: "Strategic plan, roadmap and budget"
author: "Northwind Analytics"
cover: auto
header:
left: "Northwind Analytics — Confidential"
right: "Rev. 1.0"
footer:
center: "Page {{page}} of {{pages}}"
styles:
accent: "#1B6B93"
---
# Executive Summary
Revenue grew **24%** year over year.
::: callout type="success" title="Highlight"
Operating margin expanded by ==6 pp==.
:::
| Objective | KPI target | Priority |
|-----------|-----------|----------|
| Process automation | 80% of flows | ==High== |See the full example in examples/report.md.
{
"template": "report",
"title": "FY 2026 Report",
"cover": "auto",
"styles": { "accent": "#1B6B93" },
"blocks": [
{ "type": "heading", "level": 1, "text": "Executive Summary" },
{ "type": "paragraph", "text": "Revenue grew 24% YoY." },
{ "type": "callout", "kind": "success", "title": "Highlight", "text": "Margin +6pp." }
]
}report · whitepaper · proposal · letter · memo · minutes · blank.
Every template derives its full palette from a single accent color, so
styles: { accent: "#C0392B" } re-themes the whole document.
| Block | Syntax |
|---|---|
| Headings | # H1 … #### H4 (auto-numbered in report/whitepaper) |
| Emphasis | **bold**, *italic*, `code`, ==highlight== |
| Lists | - bullet, 1. ordered, - [ ] checklist |
| Table | standard Markdown pipe table (numeric columns auto right-aligned) |
| Callout | ::: callout type="info|success|warning|danger" title="..." … ::: |
| Quote | > quoted text |
| Code | fenced ``` block |
| Signature | ::: signature name="..." role="..." date="..." … ::: |
| TOC | [[toc]] |
| Page break | \newpage |
| Cover | Content |
|---|---|
![]() |
![]() |
| Callouts & tables | Risk matrix & signatures |
![]() |
![]() |
| Valve | Default | Description |
|---|---|---|
default_template |
blank |
Template used when the spec doesn't set one |
unsplash_access_key |
"" |
Unsplash key for stock images (optional) |
image_generation_url |
"" |
OpenAI-compatible image endpoint (optional) |
image_generation_api_key |
"" |
Bearer token for image_generation_url |
docx_export_dir |
/app/backend/data/cache/files |
Fallback directory for saving |
emit_status |
true |
Emit status events in chat |
- The model produces Markdown (or JSON) and calls
generate_document. - The parser normalizes both formats into one spec, merges it with the template defaults, and resolves the accent palette.
- Each block is written as native OOXML (paragraphs, tables, shading, borders, fields).
- The
.docxis saved via the Files API (fallback/cache/files) and the link is returned in chat.
Requires python-docx, markdown-it-py, mdit-py-plugins, PyYAML (and optionally pillow/httpx):
pip install python-docx pillow httpx markdown-it-py mdit-py-plugins PyYAML
python examples/build.py # → examples/demo_report.docxThe file is designed to run inside Open WebUI: the open_webui.* imports are optional
and the tool degrades gracefully when they're missing (handy for isolated render tests).
Issues and PRs welcome. Please keep the file single-file and free of mandatory network dependencies for the core features.
MIT © IANUSTEC




