zero dependencies · MIT license

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

Command
docex replace paper.docx "268,635" "300,000" --author "Fabio"
What it looks like in Word

We analyzed 268,635300,000 political ads from the Meta Ad Library covering the 2024 election cycle.

Page 1 of 12 4,823 words
Command
docex comment paper.docx "platform governance" \
  "Added Suzor 2019 citation" --by "Fabio"
What it looks like in Word

...challenges to platform governanceFVFabio VottaJust nowAdded Suzor 2019 citation in the European context.

Command
docex style paper.docx --preset polcomm
What it looks like in Word
Political Communication
Platform Governance and Ad Transparency
Fabio Votta
This study examines the regulatory challenges facing political advertising on social media platforms...
Command
docex figure paper.docx "after:Results" fig03.png \
  --caption "Figure 3. Ad removal rates"
What it looks like in Word
fig03.png

Figure 3. Ad removal rates by platform over the campaign period.

Code
doc.after("Results").table(
  [["Party", "Ads", "Spend"],
   ["VVD",   "342", "\u20ac12,450"],
   ["D66",   "289", "\u20ac9,800"]],
  { style: "booktabs" }
);
What it looks like in Word
PartyAdsSpend
VVD342€12,450
D66289€9,800
Code
doc.at("platform governance")
   .footnote("See Suzor (2019) for a comprehensive review.");
What it looks like in Word

...challenges to platform governance1 in the European context.


1 See Suzor (2019) for a comprehensive review.

Or use the JavaScript API:

Code
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();
Result in Word

...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.

.dex source
---
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}
Rendered document

QUARTERLY Strategic SYNERGY Report

Version 47.3b (DRAFT)


Executive SummaryTIThe InternMay 13WHO WROTE THIS???

Read the full .dex specification →

48 modules. Zero dependencies.

Editing

Text & formatting

Replace, insert, delete with full formatting: bold, italic, underline (all types), strikethrough, font size, small caps, all caps, color, highlight, superscript, subscript.

Review

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.

Media

Figures & tables

Insert images with auto-dimensions. Tables with booktabs styling, cell merging, borders, shading, and widths. Bullet and numbered lists.

Structure

Headers, footers, sections

Headers and footers decompiled per-section. Multiple section properties: page size, orientation, columns, margins. Field codes, bookmarks, cross-references.

Academic

Journal styles & citations

Built-in presets for Political Communication, APA 7, JCMC, JoC. Zotero citation injection. Footnotes and endnotes with rich formatting.

Round-trip

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.

MCP config
{
  "mcpServers": {
    "docex": {
      "command": "node",
      "args": ["src/mcp-server.js"]
    }
  }
}
What the agent can do
  • 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.