Plate
PlateEditorsCreateTemplates
GitHub16kGitHub
DiscordDiscord
    • Stream
    • Copilot
    • Prompt Editor
  • Comments
  • Discussion
  • Suggestions
    • Basic Blocks
      • Blockquote
      • Heading
      • Horizontal Rule
    • Board
    • Callout
    • Code Block
    • Column
    • Date
    • Equation
    • FieldExperimental
    • Link
    • Media
    • MentionElement
    • Table
    • Table of Contents
    • Footnote
    • Details
  • Marks
    • Bold
    • Italic
    • Underline
    • Code
    • Highlight
    • Keyboard Input
    • Strikethrough
    • Subscript
    • Superscript
      • Font
      • Line Height
      • Text Align
      • Clear Formatting
      • Format Painter
    • Indent
    • List
      • Exit Break
      • Single Block
      • Trailing Block
    • Autoformat
    • Block Menu
    • Block Placeholder
    • Combobox
      • Emoji
      • MentionElement
      • Slash Command
    • Drag & Drop
    • Navigation Feedback
    • Linting
    • Tabbable
    • Toolbar
    • Yjs
    • Multi SelectEditor
    • DOCX
    • HTML
    • Markdown

DOCX

PreviousNext

Paste Word content, import bounded DOCX files, and export an explicit document projection.

Use WordPastePlugin for clipboard content. Use importDocx and exportDocx for files. The three operations have separate entrypoints and dependencies.

Loading…
Multi SelectComponents

On This Page

FeaturesKit usageInstallationAdd kitPaste from WordImport a DOCX fileLossy filesRetain the source for later exportImport commentsImport tracked revisionsImport list numberingExport a DOCX fileContent lossListsLinks and imagesSource-aware exportExport commentsStatic rendering and stylesFormat supportAPI referenceEntrypointsimportDocxDocxSourceexportDocx
Build your editor
Production-ready AI template and reusable components.
Get all-access

Features

  • Normalize HTML and RTF pasted from Microsoft Word
  • Import a bounded DOCX package into one complete editor document
  • Preserve supported Word revisions and comment ranges as structured data
  • Export one captured editor snapshot as an accepted, proposed, or review DOCX
Report an issue
Client boundary

Paste, file import, and file download use browser APIs. Keep these operations in client code. Export uses React static rendering, so pass the descriptors and static components that define your document output.

Kit usage

The app-local DocxKit installs WordPastePlugin. File import and export are standalone functions.

Installation

pnpm add platejs
pnpm add platejs

Add kit

'use client';
 
import { WordPastePlugin } from 'platejs/docx/paste';
 
export const DocxKit = [WordPastePlugin] as const;
'use client';
 
import { WordPastePlugin } from 'platejs/docx/paste';
 
export const DocxKit = [WordPastePlugin] as const;
components/editor/editor.tsx
import { createEditor } from "platejs/react";
import { DocxKit } from "@/components/editor/docx";
 
const editor = createEditor({
  plugins: [...DocxKit],
});
components/editor/editor.tsx
import { createEditor } from "platejs/react";
import { DocxKit } from "@/components/editor/docx";
 
const editor = createEditor({

Paste from Word

WordPastePlugin inlines pasted CSS and normalizes Word HTML and RTF before the installed Plate format mappings decode the content.

components/editor/editor.tsx
import { WordPastePlugin } from "platejs/docx/paste";
import { createEditor } from "platejs/react";
 
const editor = createEditor({
  plugins: [WordPastePlugin],
});
components/editor/editor.tsx
import { WordPastePlugin } from "platejs/docx/paste";
import { createEditor } from "platejs/react";
 
const editor = createEditor({
  plugins: [WordPastePlugin],
});

A pasted Word picture lands as an image when its address is http, https, blob or a raster data address. In Chrome, a picture copied from Word has a local file address, and its bytes are in the RTF copy, so WordPastePlugin rebuilds the picture from the RTF copy as a data address. A local picture that the RTF copy lacks lands as its alt text, and the paste reports it. In Safari, a picture copied from Word has a blob address, which works only in the tab that pasted it.

Word paste leaves out hidden text, rows hidden in a table copied from Excel, comment markers and the comment list. It accepts tracked changes, so inserted text lands as plain text and deleted text is left out. It reads each Word equation into an equation node as DOCX import does, or into TeX text without the equation plugins, and leaves out an equation it cannot read. Each paste reports hidden text, comments, tracked changes and unread equations once each as a lossy diagnostic, which onPasteResult receives. When nothing else remains, the paste inserts nothing, and onPasteResult receives inserted: false with those reports. When Word left something out and the cleaned HTML has more elements or deeper nesting than the HTML parser allows, the paste also inserts nothing and reports that the content is too large or too deeply nested. A Word or Excel payload over 5 MiB, the HTML byte limit, skips Word paste and pastes as plain text.

With an upload client configured, as Pasted pictures shows, each Word picture that lands as a data address uploads like a dropped file, and so does one with a blob address once the paste reads its bytes. A picture with an http or https address keeps that address. Clipboard paste does not preserve Word table geometry. Configure that destination policy in the table feature.

Import a DOCX file

importDocx reads a Blob or ArrayBuffer without modifying the editor. On success, replace the complete editor value so document metadata, named roots, and authored review state stay coherent.

Inside a mounted React control, get that complete editor with useModelEditor(). useEditor() returns the provider-selected mounted command view, whose root and authored view belong to that view.

pnpm add platejs jszip mammoth
pnpm add platejs jszip mammoth
components/editor/import-docx.tsx
import { importDocx } from "platejs/docx/import";
import { createEditor } from "platejs/react";
import { BaseEditorKit } from "@/components/editor/plugins-static";
 
const editor = createEditor({
  plugins: BaseEditorKit,
});
 
export async function importFile(file: File) {
  const result = await importDocx(file, {
    plugins: BaseEditorKit,
  });
 
  if (!result.ok) {
    return { diagnostics: result.diagnostics };
  }
 
  editor.update.value.replace(result.document);
 
  return {
    comments: result.comments,
    diagnostics: result.diagnostics,
  };
}
components/editor/import-docx.tsx
import { importDocx } from "platejs/docx/import";
import { createEditor } from "platejs/react";
import { BaseEditorKit } from "@/components/editor/plugins-static";
 
const editor = createEditor({
  plugins: BaseEditorKit,
});
 
export async function importFile(file: File) {
  const result = await importDocx(file, {
    plugins: BaseEditorKit,
  });
 
  if (!result.ok) {
    return { diagnostics: result.diagnostics };
  }
 
  editor.update.value.replace(result.document);





An expected file, package, limit, or decode failure returns { ok: false, diagnostics } and no document. An aborted import rejects with the signal reason. Invalid options and internal invariant failures throw.

Lossy files

importDocx rejects content loss by default. Import leaves out images, footnotes, endnotes, headers and footers that hold content, and the box of a checkbox that no installed HTML mapping decodes. A text box keeps its text when the file also draws it in VML that the converter reads, and is reported either way. Each of these losses fails the import with an error diagnostic, and the result is ok: false. So does markup that the HTML sanitizer removes along with content a reader would see, a comment without a complete range, or a tracked revision that the installed plugins cannot keep. Set lossPolicy: "allow" to import the rest of the file and receive the same losses as warnings:

const result = await importDocx(file, {
  lossPolicy: "allow",
  plugins: BaseEditorKit,
});
const result = await importDocx(file, {
  lossPolicy: "allow",
  plugins: BaseEditorKit,
});

An attribute or style that an HTML mapping loses warns under both policies and never fails the import. It returns a property-dropped warning whose feature names what was lost, such as data-list-type, and whose count is the number of runs, paragraphs, or cells that lost it. A loss whose mapping names no attribute is counted by its message, so links refused for different destinations warn once each. A link keeps its label when the sanitizer refuses its destination. Unless that destination could run script, the link warns the same way. For example, a numbered Word list imported without the list plugin keeps its text as paragraphs and reports its list attributes this way. When two installed marks cannot share the same text, schema fitting keeps one and returns a lossy schema-repair diagnostic instead, which follows the loss policy.

for (const diagnostic of result.diagnostics) {
  if (diagnostic.code === "property-dropped") {
    console.warn(diagnostic.feature, diagnostic.count);
  }
}
for (const diagnostic of result.diagnostics) {
  if (diagnostic.code === "property-dropped") {
    console.warn(diagnostic.feature, diagnostic.count);
  }
}

Import keeps a run's direct underline, yellow highlight, text color and background color, and a paragraph's direct center, right, end or justified alignment. Each needs its plugin installed: underline, highlight, font color, font background color or text align. Word's other named highlight colors import as a background color in the color Word draws. When a run has a highlight and shading, the highlight wins and the shading counts as dropped. A color or shading of auto reads as unset. A run with no text color imports with none, even on a dark background of its own. A theme color or patterned shading counts as dropped. When a paragraph's only text is Word symbols (w:sym), its alignment and the colors of those runs each count as dropped.

A background that is not the run's own does not import. A paragraph's own shading, a cell, row or table fill, a fill from the table style the table names, a filled text box and a page background each count as a dropped background-color. A page background counts even when Word's settings hide it. Every fill a table style sets counts, even for a part of the table that the table's look settings turn off. A run color whose contrast ratio against white is below 1.5:1 imports only when the run carries its own background or yellow highlight. Otherwise it counts as a dropped text-color, whether or not import finds a fill behind it, so white text on a dark fill that is not the run's own never comes back as white on white. Without the font background color or highlight plugin, a light color on the run's own background still imports while that background counts as dropped, so such text can show white on white.

When any part of the file, a picture included, holds a character reference that is not a decimal or hex number up to U+10FFFF, such as &#example;, import keeps no text or background color from that file. Each color it drops counts as a dropped text-color or background-color. Import ignores one with four characters or fewer between # and ;, such as &#abcd;.

Direct font size, font, caps, small caps, double strike, character spacing, line spacing, and an indent that is not zero on a paragraph outside a numbered list each return one property-dropped warning per feature, with a count. So does a mark or style that import carries when no installed plugin reads it, such as underline without the underline plugin. A Word Quote paragraph imported without the blockquote plugin keeps its paragraphs and returns a lossy unsupported-content diagnostic with action: "unwrapped", which follows the loss policy. Import ignores a style map stored in the file at mammoth/style-map, which Word never writes. When that map holds a rule, import returns one property-dropped warning with feature: "style-map". A rule is any line that is not blank and does not start with #. Mammoth 1.11 copies an includeEmbeddedStyleMap key on Object.prototype over Plate's option, and a crafted file imported earlier can set that key. While it is set, import refuses a file whose stored map holds a rule, with a decode-failed error for mammoth/style-map.

Every unsupported-content diagnostic declares impact. A lossless one never fails the import. It reports markup that import removed or unwrapped while keeping what a reader sees, such as a smart tag, a content control, a link destination that could run script, or a <style> element that a mapping added. One lossless report still loses content. Import leaves out the text inside a custom XML element.

Import neither keeps nor reports:

  • formatting that a Word style sets, such as a style's color, highlight, font size or alignment;
  • direct formatting other than what this section names, such as shadow or emboss;
  • hidden text, which imports as ordinary text;
  • a header or footer part whose name does not start with word/header or word/footer;
  • headings, links, and tables imported without their plugins, which become plain text.

A footnote or endnote reference with its own mark, such as *, leaves that mark in the text. Import leaves notes out of the text only for a note kind it reports. It reports a kind only from a part named word/footnotes.xml or word/endnotes.xml. Notes in a part under another name stay in the text with their markers and without a report. When the file also holds a default-named part of that kind with notes in it, import leaves the renamed part's notes out too, under the default-named part's report. Import reports a file entry whose name starts with word/header or word/footer but is not XML, such as a picture, as a lost header or footer. An empty header or footer paragraph counts as content when it sets a border, shading, or numbering. The setting can come from the paragraph, its style, or the document defaults, and it counts even when it draws nothing, such as a border of none. A checkbox also loses any label text that Word stores in the same w:t element as its box, under the same report.

The converter's own messages, such as one about a symbol it cannot convert, return as converter-message warnings and never fail the import.

Retain the source for later export

Set retainSource: true when the same editor imports, edits, and exports a Word file. A successful import then includes source. It is a DocxSource when exact export can return the package unchanged. Otherwise it is null, with a source-unavailable warning that names the first part exact export cannot admit. Keep the source in application state, pass it to exportDocx, and dispose it when the document closes or another file replaces it.

components/editor/docx-roundtrip.tsx
import { exportDocx } from "platejs/docx/export";
import { importDocx } from "platejs/docx/import";
 
const imported = await importDocx(file, {
  plugins: BaseEditorKit,
  retainSource: true,
});
 
if (!imported.ok) return imported.diagnostics;
 
editor.update.value.replace(imported.document);
 
const exported = await exportDocx(editor, {
  projection: "review",
  source: imported.source,
});
 
imported.source?.dispose();
components/editor/docx-roundtrip.tsx
import { exportDocx } from "platejs/docx/export";
import { importDocx } from "platejs/docx/import";
 
const imported = await importDocx(file, {
  plugins: BaseEditorKit,
  retainSource: true,
});
 
if (!imported.ok) return imported.diagnostics;
 
editor.update.value.replace(imported.document);
 
const exported = await exportDocx(editor, {
  projection: "review",
  source: imported.source,
});
 
imported.source?.dispose();

Exact export admits a closed set of passive package content:

  • the main document at word/document.xml, styles, settings, numbering, fonts, and theme;
  • headers, footers, footnotes, endnotes, and comments;
  • core, extended, and custom document properties and a thumbnail;
  • AVIF, BMP, GIF, JPEG, PNG, and WebP images reached through internal relationships;
  • hyperlinks whose destination is absolute and meets the navigation floor.

PAGE is the only recognized field instruction. Any other part, relationship, markup namespace, field instruction, or XML processing instruction leaves source null. That includes unsafe or relative hyperlinks, other external relationships, macros, ActiveX controls, OLE objects, imported HTML chunks, external templates, custom XML data other than Plate's review part, and SVG or EMF images. A null source does not mean the import lost content; exporting without a source generates the document from editor content.

DocxSource retains the admitted compressed package plus immutable document, comment, schema, and limit correspondence. It does not retain expanded ZIP entries or an editor reference. dispose() is idempotent. An export that already acquired the source can finish after disposal; later exports report source-unavailable and generate a fresh DOCX.

Import comments

The importer returns comment format facts without writing app comment storage. Each DocxComment can include a rich Plate body, an exact target.range that addresses the returned document, Word author and date metadata, a durable ID, a parent ID, and resolved state. Map those records to your app identities explicitly.

Import tracked revisions

Include AuthoredPlugin from platejs/authored in plugins to keep Word revisions. Supported insertions, deletions, moves, run property changes, and paragraph property changes then become pending authored changes. Each change takes its Word revision's ID, as docx-<id>, and its author and date. A missing author or an invalid date produces a lossy-content warning, and an invalid date imports as time 0.

Without AuthoredPlugin, or when the revisions cannot map to the installed schema, the importer flattens them into the proposed document and reports a lossy-content warning.

A file that Plate exported for review also holds Plate's review part. The importer restores each reviewed block whose Word paragraphs are unchanged since export, with its original change IDs and the document's review records. A block whose paragraphs were edited in Word imports from its Word revisions and reports a warning.

Import list numbering

Numbered and bulleted Word paragraphs become list items, and each item joins the list of its Word numbering definition. Word counts every instance of a definition in one sequence per level. A list therefore continues past other paragraphs and across instances, and lists of different definitions that interleave keep their own numbers. A level restarts after a paragraph at the level its lvlRestart names or a shallower one, which by default is the level just above it. An instance's start override resets its level once, at the instance's first paragraph at that level. That item imports with the override as listRestart, and the items after it count on from it, so an inserted item renumbers the rest the way Word does. Each item's listLevels hold its definition's level starts, lvlRestart rules and level text, with its instance's format and level text overrides applied. Word ignores a start or lvlRestart inside a level override, and so does the import. A paragraph whose instance shows its level as bullets imports as a bulleted item and does not count.

Export a DOCX file

exportDocx captures the editor once before asynchronous rendering. Pass the visible projection explicitly.

pnpm add platejs color-name html-to-vdom jszip juice katex@0.16.22 mime-types virtual-dom xmlbuilder2
pnpm add platejs color-name html-to-vdom jszip juice katex@0.16.22 mime-types virtual-dom xmlbuilder2
components/editor/export-docx.tsx
import { exportDocx } from "platejs/docx/export";
import { createEditor } from "platejs/react";
import { BaseEditorKit } from "@/components/editor/plugins-static";
import { DOCX_EXPORT_STYLES } from "@/components/editor/docx-export";
 
const editor = createEditor({ plugins: BaseEditorKit });
 
export async function downloadEditorDocx() {
  const result = await exportDocx(editor, {
    orientation: "portrait",
    projection: "proposed",
    stylesheet: DOCX_EXPORT_STYLES,
    title: "Document",
  });
 
  if (!result.ok) return result.diagnostics;
 
  const url = URL.createObjectURL(result.blob);
  const link = document.createElement("a");
  link.href = url;
  link.download = "document.docx";
  document.body.append(link);
  link.click();
  link.remove();
  URL.revokeObjectURL(url);
 
  return result.diagnostics;
}
components/editor/export-docx.tsx
import { exportDocx } from "platejs/docx/export";
import { createEditor } from "platejs/react";
import { BaseEditorKit } from "@/components/editor/plugins-static";
import { DOCX_EXPORT_STYLES } from "@/components/editor/docx-export";
 
const editor = createEditor({ plugins: BaseEditorKit });
 
export async function downloadEditorDocx() {
  const result = await exportDocx(editor, {
    orientation: "portrait",
    projection: "proposed",
    stylesheet: DOCX_EXPORT_STYLES,
    title: "Document",
  });
 
  if











Choose accepted to omit pending changes, proposed to apply them, or review to write Word tracked-change markup. Accepted and proposed exports warn about the pending changes they decided.

A review file contains what Word displays: text, comments, and tracked revisions with their authors. It also stores each top-level block that holds a pending change, with the document's review records, in a custom XML part, and binds each block to its Word paragraphs with a bookmark. Importing the file restores the blocks Word left unchanged, as Import tracked revisions describes. Export does not write named roots or document metadata to the file. To keep them, save editor.read.value() as JSON beside the file, as Serializing describes.

Content loss

exportDocx rejects content loss by default. When an image cannot be embedded, a supplied comment has no representable range, or a node has no drawing in presentation, the result is ok: false with the loss as an error diagnostic. Set lossPolicy: "allow" to download the file and receive the same loss as warnings:

const result = await exportDocx(editor, {
  comments,
  lossPolicy: "allow",
  projection: "review",
});
const result = await exportDocx(editor, {
  comments,
  lossPolicy: "allow",
  projection: "review",
});

Named roots, document metadata, removed link destinations, and other properties DOCX cannot represent are warnings under both policies. An accepted export omits a comment whose annotated content that projection excludes, and reports a warning, as Word does when the annotated suggestion is rejected.

A heading, list, table or other block inside a blockquote exports in its place but outside the quote. A blockquote inside a blockquote merges into the outer quote. Two blockquotes in a row come back from Word as one quote when the first ends and the second starts with a paragraph that is not a list item. Each case reports a quote-structure warning under both policies.

Lists

Each Plate list becomes one Word list. Its listLevels give the list's level starts, lvlRestart rules and level text. An item with listRestart, or one whose number Word would not reach, gets a numbering instance of its own that overrides that level's start, as Word's Restart Numbering writes it. The items after it count on from it in the list's own instance. Word and a re-import then show the numbers the editor shows, and the restart stays on that item. Past 9,007,199,254,740,991, the largest whole number JavaScript counts exactly, an item can continue its Word list where it should restart, so Word can show a number one higher than the editor shows. Word draws one marker style per list level, so an item whose listStyle differs from the first item at its level keeps that first style and reports a list-marker warning under both policies. A Word list level is numbered or unordered, as its first item is, and the exporter writes one set of level rules per list. Bullets and to-dos share unordered levels, and every to-do takes the document's shared to-do numbering. A numbered item at an unordered level, or the reverse, is therefore not part of its list in Word, and an item whose listLevels differ from its list's first item takes that item's rules. A kind split reports a list-structure warning, and so does a numbered or task item whose listLevels differ from its list's first numbered or task item; lossPolicy: 'reject' fails the export. A bullet without listId, as Markdown and AI output write it, stays out of the kind check, because a Markdown bullet list never shares a list with a numbered one. Word has no start that applies only when an item opens its level, and it takes each level's start from the list's first item, 1 by default. A numbered or task item whose listStart differs from the start its list's first numbered or task item gives that level exports its shown number and reports a list-start warning under both policies. Bullets take no part in the level-rule and start checks, so a bullet that leads its list gives Word its level rules and starts without a warning.

A block the list plugin targets, such as a heading, blockquote, image, toggle or code block, can be a list item, and export reads its item from the document. The block's first Word paragraph carries the item's marker and counts once in its list. Each later paragraph the block writes, such as an image caption, a toggle body or the second paragraph of a blockquote, sits at the item's text indent with no marker. A heading keeps its heading style and bookmark, and a blockquote or toggle keeps its own style on every paragraph. A listed blockquote that starts with a table writes its number on an empty paragraph above the table, and a listed block that writes no paragraph keeps its number on an empty paragraph. A listed blockquote gets the same quote-structure warnings as a plain one. An image in a list item fits the item's text width. A table cell exports its blocks as the body does, and a nested table and its images fit the cell that holds them, less the cell's padding.

Links and images

Export writes a link destination only when it is absolute and meets the navigation floor, such as https: or mailto:. It writes bookmark links such as #introduction as Word anchors. An unsafe destination, or a relative link that has no document base in a Word file, keeps its text without the destination.

Images are embedded as PNG, JPEG, GIF, or BMP. Set allowRemoteImages: true to fetch HTTP(S) images during export. These images are omitted and leave their alt text:

  • an image with an unsafe, relative, or blob source;
  • a remote image when allowRemoteImages is off;
  • an image that cannot be fetched;
  • an image in any other format.

Before returning a generated file, export checks the written package against the same passive vocabulary that retained sources use. Output outside it is withheld with an invalid-package error. An unchanged source-aware export returns the retained file, which passed the same check when it was imported.

Source-aware export

With a valid source, an unchanged review export returns the admitted file byte for byte. Exact reuse requires the same compiled schema, an unchanged review document, unchanged or omitted comments, no title, margins, orientation, pageSize, stylesheet, or fontFamily option, and no pageNumber: true. component and presentation do not apply on this path, because export regenerates nothing.

If an exact check fails, exportDocx regenerates the complete document body. It keeps these source units when their internal relationships are closed, reachable, and nonconflicting:

  • headers and footers from a document with one section, including their images and hyperlinks;
  • custom document properties.

The regenerated package has its own core document properties. It omits source body XML, body-only parts such as footnotes and body images, and headers and footers from a document with multiple sections. It also omits the source core and extended properties and the package thumbnail: the core properties, such as the author, title and creation date, the extended properties, which count pages and words and hold details such as the company name, and the thumbnail, which pictures the body. Diagnostics report why the source was rewritten and identify each omitted source part. A custom property linked to body text keeps the value cached in the source file, even when the edit changed that text.

When regeneration is required, omitted comments means that no comments are generated. Pass the current app-owned comment set explicitly to retain comments after an edit. Imported comment ranges are not relocated automatically.

Export comments

Pass comments whose ranges address the editor's stored document, the value editor.read.value() returns. Export maps those ranges into accepted or proposed output before rendering:

const result = await exportDocx(editor, {
  comments,
  projection: "review",
});
const result = await exportDocx(editor, {
  comments,
  projection: "review",
});

The same configured static renderer handles the main document and rich comment bodies. Under the default lossPolicy, a comment without a complete range fails the export; with lossPolicy: "allow" the export omits it with a warning.

Static rendering and styles

DOCX owns its semantic static mappings for code blocks, columns, equations, callouts, headings, lists, and tables of contents. They set no color, font, or font size beyond an element's own values, such as a callout's color. The app's stylesheet sets them and can select:

  • editor-<plugin name>, the class on each drawn element, such as .editor-codeBlock;
  • [data-docx-list], a listed block, whose value is bulleted, numbered or task, with data-docx-list-checked on a checked to-do, such as [data-docx-list="task"][data-docx-list-checked]. A rule there styles the block's own element, and the rule's alignment and line height apply to each text paragraph the block writes, not to an image or a table;
  • table > tbody > tr > td inside a callout, whose first cell holds the icon;
  • [data-docx-preserve-whitespace], the text of a code block;
  • [data-empty], the placeholder of an empty equation or table of contents.

The top and bottom margin, in pt or px, of a paragraph, heading or other block drawn as one Word paragraph sets its Word space before and after. A margin on a list, list item or table does not reach the file. Without a margin, the Word paragraph and heading styles set that spacing.

What the stylesheet adds to a run, such as a heading's size or a header cell's bold, exports as a Word character style named Plate Look. Runs that need a different look get Plate Look 2, Plate Look 3 and so on. Each style leaves out what the paragraph's Word style already sets, because Word turns bold off when two style levels both turn it on. Direct run formatting in the file holds only a node's own marks and style. When a custom component puts a span inside strong or b, the content after that element in the same parent also exports as direct bold. Paragraph alignment, spacing and line height export as direct paragraph formatting.

Each paragraph of a blockquote takes Word's Quote paragraph style. Inline code and keyboard text take the HTML Code, HTML Keyboard and HTML Code Keyboard character styles. These styles carry the stylesheet's blockquote, code and kbd rules. A code or keyboard run gets a numbered copy of its style, such as HTML Code 2, when it also sits in a link, when the stylesheet gives it a look its style lacks, or when both its style and its paragraph style are bold. Import reads these styles and their numbered copies back as a blockquote and as code and kbd marks. A numbered copy whose name element also declares a namespace prefix named val imports as plain text with a warning. A Plate Look style adds no mark, so a heading or header cell comes back without a bold mark.

The app may pass a custom root component when it needs a different wrapper. DOCX_EXPORT_STYLES is the registry's copied presentation preset.

Equations export as Word math built from KaTeX's MathML. An equation that uses notation the converter does not cover, such as a matrix, exports its TeX as text inside a Word equation. A to-do list item exports with a ☑ or ☐ list marker from its checked value, and import reads a bullet level drawn as ☐, ☑ or ☒ as a task item with its checked state.

A live editor's components are editing UI. Pass the app's static kit as presentation so the body and every comment body draw with static components of the same plugin name. A plugin with no static version exports its content without its component or wrapper and reports a missing-static-presentation diagnostic, which counts as lost content under lossPolicy.

export const DOCX_EXPORT_STYLES = `
body {
  font-family: 'Calibri', 'Arial', sans-serif;
  font-size: 11pt;
  line-height: 1.5;
  color: #000;
  margin: 0;
  padding: 20px;
}
h1 { font-size: 24pt; font-weight: bold; margin: 24pt 0 12pt 0; }
h2 { font-size: 18pt; font-weight: bold; margin: 18pt 0 10pt 0; }
h3 { font-size: 14pt; font-weight: bold; margin: 14pt 0 8pt 0; }
h4 { font-size: 12pt; font-weight: bold; margin: 12pt 0 6pt 0; }
h5 { font-size: 11pt; font-weight: bold; margin: 11pt 0 6pt 0; }
h6 { font-size: 10pt; font-weight: bold; margin: 10pt 0 6pt 0; }
p { margin: 0 0 8pt 0; }
ul, ol { margin: 0 0 8pt 0; padding-left: 20pt; }
li { margin: 0 0 4pt 0; }
strong, b { font-weight: bold; }
em, i { font-style: italic; }
u { text-decoration: underline; }
s, strike, del { text-decoration: line-through; }
code {
  font-family: 'Courier New', Consolas, monospace;
  background-color: #f5f5f5;
  padding: 2px 4px;
  border-radius: 3px;
}
pre {
  font-family: 'Courier New', Consolas, monospace;
  background-color: #f5f5f5;
  padding: 10px;
  margin: 0 0 8pt 0;
  white-space: pre-wrap;
  border-radius: 4px;
}
.hljs-keyword, .hljs-doctag, .hljs-template-tag, .hljs-template-variable, .hljs-type, .hljs-variable.language_ { color: #d13344; }
.hljs-attr, .hljs-attribute, .hljs-literal, .hljs-meta, .hljs-number, .hljs-operator,
.hljs-selector-attr, .hljs-selector-class, .hljs-selector-id, .hljs-variable { color: #005cc5; }
.hljs-built_in, .hljs-symbol { color: #bc4f01; }
.hljs-bullet { color: #735c0f; }
.hljs-comment, .hljs-code, .hljs-formula { color: #68717b; }
.hljs-name, .hljs-quote, .hljs-selector-tag, .hljs-selector-pseudo { color: #1b8136; }
.hljs-regexp, .hljs-string, .hljs-meta .hljs-string { color: #032f62; }
.hljs-section { color: #005cc5; }
.hljs-title, .hljs-title.class_, .hljs-title.class_.inherited__, .hljs-title.function_ { color: #6f42c1; }
.hljs-addition { color: #1b8136; background-color: #f0fff4; }
.hljs-deletion { color: #b31d28; background-color: #ffeef0; }
.hljs-emphasis { font-style: italic; }
.hljs-section, .hljs-strong { font-weight: bold; }
blockquote {
  border-left: 3px solid #ccc;
  margin: 0 0 8pt 0;
  padding-left: 10pt;
  color: #666;
  font-style: italic;
}
table {
  border-collapse: collapse;
  width: 100%;
  margin: 0 0 8pt 0;
}
th, td {
  border: 1px solid #ccc;
  padding: 6pt;
  text-align: left;
}
th {
  background-color: #f5f5f5;
  font-weight: bold;
}
a {
  color: #0066cc;
  text-decoration: underline;
}
img {
  max-width: 100%;
  height: auto;
}
hr {
  border: none;
  border-top: 1px solid #ccc;
  margin: 12pt 0;
}
sup { vertical-align: super; font-size: 8pt; }
sub { vertical-align: sub; font-size: 8pt; }
mark { background-color: #ffff00; }
.editor-callout > table > tbody > tr > td { background-color: #f4f4f5; }
.editor-callout > table > tbody > tr > td:first-child {
  font-family: "Apple Color Emoji", "Segoe UI Emoji", NotoColorEmoji, "Noto Color Emoji", "Segoe UI Symbol", "Android Emoji", EmojiSymbols;
  font-size: 18px;
}
.editor-codeBlock > [data-docx-preserve-whitespace] {
  background-color: #f5f5f5;
  font-family: 'Courier New', Consolas, monospace;
  font-size: 10pt;
}
.editor-equation [data-empty],
.editor-inlineEquation [data-empty] { color: #888; }
.editor-toc [data-empty] { color: #666; font-size: 10pt; }
`.trim();
export const DOCX_EXPORT_STYLES = `
body {
  font-family: 'Calibri', 'Arial', sans-serif;
  font-size: 11pt;
  line-height: 1.5;
  color: #000;
  margin: 0;
  padding: 20px;
}
h1 { font-size: 24pt; font-weight: bold; margin: 24pt 0 12pt 0; }
h2 { font-size: 18pt; font-weight: bold; margin: 18pt 0 10pt 0; }
h3 { font-size: 14pt; font-weight: bold; margin: 14pt 0 8pt 0; }
h4 { font-size: 12pt; font-weight: bold; margin: 12pt 0 6pt 0; }
h5 { font-size: 11pt; font-weight: bold; margin: 11pt 0 6pt 0; }
h6 { font-size: 10pt; font-weight: bold; margin: 10pt 0 6pt 0; }
p { margin: 0 0 8pt 0; }
ul, ol { margin: 0 0 8pt 0; padding-left: 20pt; }
li { margin: 0 0 4pt 0; }
strong, b { font-weight: bold; }
em, i { font-style: italic; }
u { text-decoration: underline; }
s, strike, del { text-decoration: line-through; }
code {
  font-family: 'Courier New', Consolas, monospace;
  background-color: #f5f5f5;











































































Format support

ContentBehavior
Paragraphs, headings, supported marks and propertiesDecode through the installed HTML mappings and export through the configured static renderer
Lists, links, bookmarks, rows, cells, and spansPreserve supported semantic structure; omit Word layout details with diagnostics
Tracked revisionsPreserve supported insert, delete, move, run-property, and paragraph-property changes when plugins include AuthoredPlugin; otherwise flatten with a lossy-content warning
Main-body commentsPreserve rich bodies, ranges, author/date metadata, durable IDs, replies, and resolved state when present
Embedded images during importOmit the resource and return a resource-omitted diagnostic
Links and images during exportWrite absolute navigation-safe links and PNG, JPEG, GIF, or BMP images; report removed destinations and omitted images
Single-section headers and footersKeep safe closed source subgraphs during source-aware export; do not map them into the editor document. Import reports one that holds content as dropped
Multiple-section headers and footers, footnotes, and endnotesInspect and bound their package parts; omit them from edited source-aware output with diagnostics. Import reports them as dropped content, except a part that draws nothing, such as one that holds only Word's separator notes or an empty styled paragraph
Fields, text boxes, shapes, charts, SmartArt, and embedded objectsKeep reachable plain text when conversion exposes it; report unsupported or omitted content
Plate named roots and metadataOmit from Word output with a lossy-content warning; keep them in authored JSON
EquationsExport as Word math, or as TeX inside a Word equation when the converter does not cover the notation. Import reads Word math into equation and inlineEquation nodes, with TeX rebuilt from the equation's structure, or into TeX text when those plugins are not installed. A display equation that shares its paragraph with a comment, tracked change or text, or sits in a list item or an indented paragraph, imports inline
Task listsGive a to-do item a ☑ or ☐ list marker from its checked value; import a bullet level drawn as ☐, ☑ or ☒ as a task item with its checked state
Custom Plate, emoji, and media nodesUse their configured static serializers; unsupported output produces diagnostics

API reference

Entrypoints

SurfaceImport path
WordPastePluginplatejs/docx/paste
importDocx and import typesplatejs/docx/import
exportDocx and export typesplatejs/docx/export

importDocx

importDocx(
  source: ArrayBuffer | Blob,
  options: DocxImportOptions
): Promise<DocxImportResult>
importDocx(
  source: ArrayBuffer | Blob,
  options: DocxImportOptions
): Promise<DocxImportResult>

DocxImportOptions requires plugins and accepts schema, a cooperative signal, lossPolicy, partial limits overrides, and retainSource. Import captures that detached target before its first await and never reads a live editor or mutable plugin store. Every limit must be a positive safe integer. Literal retainSource: true conditionally adds source: DocxSource | null to a successful result; omitted or literal false does not.

Default limitValue
maxInputBytes32 MiB
maxEntries1,024
maxEntryBytes32 MiB
maxExpandedBytes128 MiB
maxRelationships4,096
maxRevisions2,000
maxComments5,000
maxXmlDepth128
maxXmlNodes500,000

A successful result contains document, comments, and structured diagnostics. A retained success also contains source, which is null when exact export cannot admit the package. A failed result contains only diagnostics.

DocxSource

class DocxSource {
  private constructor();
  dispose(): void;
}
class DocxSource {
  private constructor();
  dispose(): void;
}

Only importDocx creates a DocxSource. The object is process-local and cannot be serialized or reattached. To restore source-aware export after application reload, keep the original file and import it again.

exportDocx

exportDocx(
  editor: Editor,
  options: DocxExportOptions
): Promise<DocxExportResult>
exportDocx(
  editor: Editor,
  options: DocxExportOptions
): Promise<DocxExportResult>
OptionTypeDescription
projection'accepted' | 'proposed' | 'review'Required visible document projection
commentsreadonly DocxComment[]Comment records whose ranges address the stored document
allowRemoteImagesbooleanFetch remote HTTP(S) images to embed; defaults to false
componentReact.ComponentType<EditorStaticProps>Optional static editor wrapper
fontFamilystringDocument body font; rebuilds an unchanged source
lossPolicy'allow' | 'reject'Fail on dropped content, or return it as warnings; defaults to 'reject'
marginsMarginsPage margins in twentieths of a point
orientation'landscape' | 'portrait'Page orientation
pageNumberbooleanNumber the pages in a footer; defaults to false. With true, rebuilds an unchanged source, replaces its default footer and fills its empty first-page and even-page footers
pageSizePageSizePage dimensions in twentieths of a point
presentationreadonly BasePluginInput[]Static plugins that draw the body and comment bodies, matched by plugin name
signalAbortSignalCooperative cancellation signal
sourceDocxSource | nullRetained source correspondence for exact or safe export
stylesheetstringCSS that sets the Word look; rebuilds an unchanged source
titlestringDocument metadata title

A successful result contains blob and structured diagnostics. A failed result contains only diagnostics.

See Authored Changes for the editor's accepted, proposed, and review projections.

plugins: [...DocxKit],
});
return {
comments: result.comments,
diagnostics: result.diagnostics,
};
}
(
!
result.ok)
return
result.diagnostics;
const url = URL.createObjectURL(result.blob);
const link = document.createElement("a");
link.href = url;
link.download = "document.docx";
document.body.append(link);
link.click();
link.remove();
URL.revokeObjectURL(url);
return result.diagnostics;
}
padding: 2px 4px;
border-radius: 3px;
}
pre {
font-family: 'Courier New', Consolas, monospace;
background-color: #f5f5f5;
padding: 10px;
margin: 0 0 8pt 0;
white-space: pre-wrap;
border-radius: 4px;
}
.hljs-keyword, .hljs-doctag, .hljs-template-tag, .hljs-template-variable, .hljs-type, .hljs-variable.language_ { color: #d13344; }
.hljs-attr, .hljs-attribute, .hljs-literal, .hljs-meta, .hljs-number, .hljs-operator,
.hljs-selector-attr, .hljs-selector-class, .hljs-selector-id, .hljs-variable { color: #005cc5; }
.hljs-built_in, .hljs-symbol { color: #bc4f01; }
.hljs-bullet { color: #735c0f; }
.hljs-comment, .hljs-code, .hljs-formula { color: #68717b; }
.hljs-name, .hljs-quote, .hljs-selector-tag, .hljs-selector-pseudo { color: #1b8136; }
.hljs-regexp, .hljs-string, .hljs-meta .hljs-string { color: #032f62; }
.hljs-section { color: #005cc5; }
.hljs-title, .hljs-title.class_, .hljs-title.class_.inherited__, .hljs-title.function_ { color: #6f42c1; }
.hljs-addition { color: #1b8136; background-color: #f0fff4; }
.hljs-deletion { color: #b31d28; background-color: #ffeef0; }
.hljs-emphasis { font-style: italic; }
.hljs-section, .hljs-strong { font-weight: bold; }
blockquote {
border-left: 3px solid #ccc;
margin: 0 0 8pt 0;
padding-left: 10pt;
color: #666;
font-style: italic;
}
table {
border-collapse: collapse;
width: 100%;
margin: 0 0 8pt 0;
}
th, td {
border: 1px solid #ccc;
padding: 6pt;
text-align: left;
}
th {
background-color: #f5f5f5;
font-weight: bold;
}
a {
color: #0066cc;
text-decoration: underline;
}
img {
max-width: 100%;
height: auto;
}
hr {
border: none;
border-top: 1px solid #ccc;
margin: 12pt 0;
}
sup { vertical-align: super; font-size: 8pt; }
sub { vertical-align: sub; font-size: 8pt; }
mark { background-color: #ffff00; }
.editor-callout > table > tbody > tr > td { background-color: #f4f4f5; }
.editor-callout > table > tbody > tr > td:first-child {
font-family: "Apple Color Emoji", "Segoe UI Emoji", NotoColorEmoji, "Noto Color Emoji", "Segoe UI Symbol", "Android Emoji", EmojiSymbols;
font-size: 18px;
}
.editor-codeBlock > [data-docx-preserve-whitespace] {
background-color: #f5f5f5;
font-family: 'Courier New', Consolas, monospace;
font-size: 10pt;
}
.editor-equation [data-empty],
.editor-inlineEquation [data-empty] { color: #888; }
.editor-toc [data-empty] { color: #666; font-size: 10pt; }
`.trim();