Formatter for Word documents (.docx) and Google Docs - like Prettier, but for documents.
Every team has that one document. The one where half the text is in Arial, the other half in Times New Roman, headings are inconsistent, line spacing changes mid-page, and margins are different on every section.
Manual formatting is tedious, error-prone, and never consistent across a team. Code has Prettier. Documents deserve the same.
DocFormatter is a CLI tool and library for automatic, deterministic formatting
of Word documents (.docx) and Google Docs. You define a style config once -
DocFormatter enforces it everywhere.
Just like Prettier stops arguments about code style - DocFormatter stops arguments about fonts, spacing, and heading styles in documents.
- 🎯 Automatically apply a defined style to any
.docxdocument - 🎯 Support for Google Docs via the official REST API
- 🎯 Configurable via
.docformatterrcordocformatter.config.js - 🎯 Advanced Scripting: Write complex formatting logic in Lua (safe & fast)
- 🎯 CLI with
formatandcheckcommands - 🎯 CI/CD friendly - exit with non-zero code if document is not formatted
- 🎯 Never touch content - only formatting, never text
- ❌ Not a text or content editor
- ❌ Not a file format converter (docx → pdf, etc.)
- ❌ Not a grammar or spell checker
- ❌ Not a replacement for Word or Google Docs
| Audience | Use Case |
|---|---|
| Technical writers | Standardize documentation style across teams |
| Legal teams | Enforce consistent formatting in contracts and reports |
| Developers | Auto-format docs in CI/CD pipelines |
| Students & educators | Apply university/company templates instantly |
| Open source projects | Keep contribution docs visually consistent |
While basic rules (font, margins) are configured in JSON, complex logic needs a real language. DocFormatter embeds a lightweight Lua engine to let you write custom checks without security risks.
Example Custom Rule (rules/legal-headers.lua):
-- If a paragraph starts with "Section X.Y", make it Bold + Uppercase
function check_paragraph(text, style)
if text:match("^Section %d+%.%d+") then
style.bold = true
style.caps = true
return style
end
end- Runtime: Node.js + TypeScript
.docxparsing:docxtemplater+pizzip- XML processing:
fast-xml-parserfor OOXML manipulation - Plugin Engine: Lua (via
wasmoon- WebAssembly) for user-defined rules - Google Docs: Google Docs REST API v1
- CLI:
commander.js - Config resolution:
cosmiconfig(same as Prettier)
vitestfor unit and integration tests- Fixture
.docxfiles for formatting snapshot tests
- MVP: .docx formatting (font family, size, paragraph spacing)
- Heading styles (H1–H6), page margins, page size
- CLI with format and check commands
- Config file support via cosmiconfig
- Pluggable rules API with custom rule support
- Google Docs API integration
- VSCode extension
- Stable release, full documentation, real-world examples
- Prettier - the gold standard for opinionated code formatting
- Biome - fast formatter and linter for JavaScript/TypeScript
- textlint - pluggable linter for natural language text
- markdown-styler-for-word - applies styles to markdown docs in Word
- python-docx - Python library for reading/writing .docx files
- docxtemplater - generate .docx from templates
The project is in the concept stage. All feedback, ideas, and suggestions are very welcome - open an Issue to start a discussion.
Once the initial architecture is defined, a CONTRIBUTING.md will be published
with setup instructions, code style guidelines, and a guide for writing custom rules.
MIT © 2026 - see LICENSE for details.