docex
Edit Word documents with code. Convert .docx to plain text and back with zero data loss. Built for academic manuscripts, works on any .docx.
Your document, three ways
Collaborators use Word. You use a text editor. Git tracks every change. docex bridges all three.
Respond to peer review in 3 commands
docex replace paper.docx "268,635" "300,000" --author "Fabio"
We analyzed 268,635300,000 political ads from the Meta Ad Library covering the 2024 election cycle.
docex comment paper.docx "platform governance" \
"Added Suzor 2019 citation" --by "Fabio"
...challenges to platform governanceFVFabio VottaJust nowAdded Suzor 2019 citation in the European context.
docex style paper.docx --preset polcomm
docex figure paper.docx "after:Results" fig03.png \
--caption "Figure 3. Ad removal rates"
Figure 3. Ad removal rates by platform over the campaign period.
doc.after("Results").table(
[["Party", "Ads", "Spend"],
["VVD", "342", "\u20ac12,450"],
["D66", "289", "\u20ac9,800"]],
{ style: "booktabs" }
);
| Party | Ads | Spend |
|---|---|---|
| VVD | 342 | €12,450 |
| D66 | 289 | €9,800 |
doc.at("platform governance")
.footnote("See Suzor (2019) for a comprehensive review.");
...challenges to platform governance1 in the European context.
1 See Suzor (2019) for a comprehensive review.
Or use the JavaScript API:
const doc = docex("paper.docx");
doc.author("Fabio Votta");
doc.replace("enforcement gap", "regulatory gap");
doc.at("platform governance")
.comment("Added Suzor 2019 citation");
doc.after("Methods")
.insert("We used a mixed-methods approach.");
await doc.save();
...the enforcement gapregulatory gap remains a key challenge in platform governanceFVFabio VottaJust nowAdded Suzor 2019 citation.
We used a mixed-methods approach.
Every .docx becomes readable plain text
Every font, color, comment, tracked change, footnote, and formatting detail survives the round trip. Nothing is lost.
---
docex: "0.4.0"
authors:
- name: "The Intern"
---
# QUARTERLY Strategic SYNERGY Report {id:BABCF972}
{p id:9E7DD00E}
{font "Lucida Handwriting"}{color 999999}Version 47.3b (DRAFT){/color}{/font}
{/p}
{pagebreak}
### Executive Summary {id:043C8211}
{comment id:0 by:"The Intern"}
WHO WROTE THIS???
{/comment}
QUARTERLY Strategic SYNERGY Report
Version 47.3b (DRAFT)
Executive SummaryTIThe InternMay 13WHO WROTE THIS???
48 modules. Zero dependencies.
Text & formatting
Replace, insert, delete with full formatting: bold, italic, underline (all types), strikethrough, font size, small caps, all caps, color, highlight, superscript, subscript.
Comments & tracked changes
Comments anchored to specific text with inline markers. Tracked changes preserve formatting. Move tracking, format changes, accept/reject individually or in bulk.
Figures & tables
Insert images with auto-dimensions. Tables with booktabs styling, cell merging, borders, shading, and widths. Bullet and numbered lists.
Headers, footers, sections
Headers and footers decompiled per-section. Multiple section properties: page size, orientation, columns, margins. Field codes, bookmarks, cross-references.
Journal styles & citations
Built-in presets for Political Communication, APA 7, JCMC, JoC. Zotero citation injection. Footnotes and endnotes with rich formatting.
40+ OOXML features
Lossless .dex round-trip preserves tabs, bookmarks, hyperlinks, math equations, text boxes, content controls, ruby text, field codes, and embedded objects.
Let Claude edit your manuscript
docex includes an MCP server. Any MCP-compatible AI agent can open your .docx, make tracked changes, add comments, and save.
{
"mcpServers": {
"docex": {
"command": "node",
"args": ["src/mcp-server.js"]
}
}
}
- Replace text with tracked changes
- Add comments anchored to specific text
- Insert figures, tables, footnotes, endnotes
- Apply journal formatting presets
- Lossless .dex round-trip (40+ OOXML features)
- Headers, footers, field codes, bookmarks
- Math equations, content controls, text boxes
- Validate for submission
Zero dependencies. Just clone and go.
git clone https://github.com/favstats/docex.git && cd docex
Requires Node.js 18+. No npm install needed.