# @docen/docx

> DOCX editor and converter powered by @office-open/docx with a Tiptap editing layer — bidirectional DOCX and Markdown conversion, styled HTML paste input

Latest version **0.7.0** (published 2026-09-07) · MIT license · 0 weekly downloads

## Install

```sh
npm install @docen/docx
pnpm add @docen/docx
yarn add @docen/docx
bun add @docen/docx
```

## Health

**Score 65/100 (B)** — status: active.

Positive: has types; esm support; no vulnerabilities; recently updated; high maintenance score.

Warnings: low downloads; pre 1.0.

## Facts

| | |
|---|---|
| Version | 0.7.0 |
| Published | 2026-09-07 |
| First published | 2026-06-14 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 9 |
| Unpacked size | 345.4 KB |
| Known vulnerabilities | 0 (+2 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 71 |
| Author | Demo Macro |
| Maintainers | demomacro |
| Keywords | converter, docen, docx, editor, markdown, microsoft-word, office, ooxml, rich-text, tiptap, typescript, wysiwyg |

## Links

- npm: https://www.npmjs.com/package/@docen/docx
- Repository: https://github.com/DemoMacro/docen
- Homepage: https://github.com/DemoMacro/docen#readme
- Issues: https://github.com/DemoMacro/docen/issues
- npm.io page: https://npm.io/package/@docen/docx

## Dependencies (9)

- [@tiptap/pm](https://npm.io/package/@tiptap/pm.md) 3.29.2
- [image-meta](https://npm.io/package/image-meta.md) 0.2.2
- [@tiptap/core](https://npm.io/package/@tiptap/core.md) 3.29.2
- [@docen/layout](https://npm.io/package/@docen/layout.md) 0.7.0
- [@tiptap/markdown](https://npm.io/package/@tiptap/markdown.md) 3.29.2
- [@office-open/core](https://npm.io/package/@office-open/core.md) 0.14.4
- [@office-open/docx](https://npm.io/package/@office-open/docx.md) 0.14.4
- [leafer-x-metafile](https://npm.io/package/leafer-x-metafile.md) 0.2.0
- [@tiptap/extension-link](https://npm.io/package/@tiptap/extension-link.md) 3.29.2

## Alternatives

- [ext-list](https://npm.io/package/ext-list.md) — 6.3M weekly downloads
- [@lexical/selection](https://npm.io/package/@lexical/selection.md) — 3.8M weekly downloads
- [@lexical/text](https://npm.io/package/@lexical/text.md) — 3.6M weekly downloads
- [@lexical/clipboard](https://npm.io/package/@lexical/clipboard.md) — 3.0M weekly downloads
- [@tiptap/extension-mention](https://npm.io/package/@tiptap/extension-mention.md) — 3.0M weekly downloads

## Recent versions

- 0.7.0 (latest) — 2026-09-07
- 0.6.2 — 2026-09-01
- 0.6.1 — 2026-08-31
- 0.6.0 — 2026-08-30
- 0.5.5 — 2026-08-06
- 0.5.4 — 2026-08-05
- 0.5.3 — 2026-07-14
- 0.5.2 — 2026-07-13
- 0.5.1 — 2026-07-05
- 0.5.0 — 2026-07-05
- 0.4.1 — 2026-07-05
- 0.4.0 — 2026-07-04
- 0.3.5 — 2026-07-02
- 0.3.4 — 2026-07-01
- 0.3.3 — 2026-06-29
- … 3 more at https://npm.io/package/@docen/docx/versions

## README

# @docen/docx

![npm version](https://img.shields.io/npm/v/@docen/docx)
![npm downloads](https://img.shields.io/npm/dw/@docen/docx)
![npm license](https://img.shields.io/npm/l/@docen/docx)

> DOCX editor and converter powered by @office-open/docx with Tiptap editing layer, supporting bidirectional conversion between DOCX and Markdown (styled HTML is accepted as paste input).

> Need a ready-made visual editor? [`@docen/editor`](../editor/README.md) wraps this engine in a Fluent UI host with the turnkey `<docen-document>` web component.

## Features

- 📝 **Viewless Tiptap engine** — the DOCX editing model with DOCX-aware extensions; rendering belongs to the host (e.g. @docen/editor's canvas stage)
- 🔄 **DOCX Round-trip** — Near-lossless DOCX ↔ Editor conversion via @office-open/docx
- 📄 **Markdown Support** — Tiptap JSON ↔ Markdown conversion
- 🎨 **DOCX Properties** — Custom Tiptap extensions carry shading, borders, indent, spacing, floating, crop
- 🔗 **Template Patching** — Replace `{{placeholders}}` in DOCX templates with Tiptap-JSON content

## Installation

```bash
# Install with pnpm
$ pnpm add @docen/docx

# Install with npm
$ npm install @docen/docx
```

## Quick Start

```typescript
import { docxExtensions, parseDOCX, generateDOCX } from "@docen/docx";
import { Editor } from "@docen/docx/core";

// Viewless: the editor is the editing model — rendering belongs to the host.
const editor = new Editor({
  element: null,
  extensions: docxExtensions,
  content: await parseDOCX(buffer),
});

// Save back to DOCX
const output = await generateDOCX(editor.getJSON());
```

## API

### Standalone Functions (Core)

These work without an editor instance — for headless/server/batch use.

```typescript
import {
  parseDOCX,
  generateDOCX,
  generateDOCXSync,
  generateDOCXStream,
  parseMarkdown,
  generateMarkdown,
} from "@docen/docx";

// DOCX pipeline: DOCX binary ↔ Tiptap JSON
const json = parseDOCX(buffer); // → JSONContent
const buffer = await generateDOCX(json); // → Buffer (pre-fetches http images by default)
const blob = await generateDOCX(json, { packer: { type: "blob" } }); // → Blob
const sync = generateDOCXSync(json); // → Buffer (skips prepare)
const stream = await generateDOCXStream(json); // → ReadableStream<Uint8Array>

// Markdown pipeline: Markdown string ↔ Tiptap JSON
const json = parseMarkdown("# Hello"); // → JSONContent
const md = generateMarkdown(json); // → string
```

### Editor

```typescript
import { createDocxEditor, docxExtensions } from "@docen/docx";

const editor = createDocxEditor({
  element: document.querySelector("#editor"),
  extensions: docxExtensions,
  spellcheck: true,
  editable: true,
});
```

Need a ready-made editor UI? [`@docen/editor`](../editor/README.md)'s `<docen-document>` bundles this engine with open/save, canvas rendering, and the Fluent host.

### Template Patching

Replace `{{placeholders}}` in a DOCX template with Tiptap-JSON content. Each
patch's `content` is prepared (default: fetch http images) then compiled to DOCX.

```typescript
import { patchDOCX, parseMarkdown } from "@docen/docx";

const result = await patchDOCX({
  template: templateBuffer,
  patches: {
    title: { content: parseMarkdown("# Report") },
  },
  outputType: "nodebuffer",
});
```

### Advanced: Model Bridge

`generateDOCX` runs `prepareDocument → compileDocument → generateDocument`
internally. You rarely need these directly — reach for them only when working
with the intermediate `DocumentOptions` (the OOXML persistence model):

```typescript
import { resolveDocument, compileDocument, prepareDocument } from "@docen/docx";

const json = resolveDocument(docOpts); // DocumentOptions → JSONContent
const docOpts = compileDocument(json); // JSONContent → DocumentOptions
await prepareDocument(json); // in place: http image URLs → data URLs
```

## Architecture

```
Standalone Functions (core)
  parseDOCX / generateDOCX / generateDOCXSync / generateDOCXStream / patchDOCX
  parseMarkdown / generateMarkdown
  resolveDocument / compileDocument / prepareDocument  (model bridge, advanced)
        ↕ used by
createDocxEditor / docxExtensions — the viewless Tiptap editing model
        ↕ rendered by
@docen/editor's canvas stage (LeaferJS pages, caret/selection mapping)
```

- **Runtime model**: Tiptap JSON with DOCX-rich attributes via custom extensions
- **Persistence model**: DocumentOptions (complete OOXML expressiveness)
- **Standalone functions are core** — the editor bindings are thin wrappers

## License

- [MIT](../../LICENSE) &copy; [Demo Macro](https://www.demomacro.com/)

---
_Source: https://npm.io/package/@docen/docx · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
