{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "docx-io-docs",
  "title": "DOCX Import/Export",
  "description": "Import DOCX files and export Plate content to Word documents.",
  "files": [
    {
      "path": "../../content/docs/(plugins)/(serializing)/docx-io.mdx",
      "content": "---\ntitle: DOCX Import/Export\ndescription: Import DOCX files and export Plate content to Word documents.\n---\n\n<PackageInfo>\n\n## Features\n\n- **Import DOCX files** to Plate format with full content and comment extraction\n- **Export to DOCX** with support for all common formatting, tables, lists, and images\n- Support for headers, footers, page orientation, and margins\n- Configurable CSS styles and fonts for export\n\n</PackageInfo>\n\n<Callout type=\"info\">\n  Looking for paste from Word support? See [DOCX Paste](/docs/docx).\n</Callout>\n\n## Installation\n\n```bash\nnpm install @platejs/docx-io\n```\n\n## Import DOCX\n\n<Steps>\n\n### Import DOCX File\n\nUse `importDocx` to convert a DOCX file to Plate nodes:\n\n```tsx\nimport { importDocx } from '@platejs/docx-io';\n\nconst handleFileUpload = async (file: File) => {\n  const arrayBuffer = await file.arrayBuffer();\n  const result = await importDocx(editor, arrayBuffer);\n\n  // Insert nodes into editor\n  editor.tf.insertNodes(result.nodes);\n\n  // Handle comments if needed\n  for (const comment of result.comments) {\n    console.log(`Comment ${comment.id}: ${comment.text}`);\n  }\n\n  // Check for conversion warnings\n  if (result.warnings.length > 0) {\n    console.warn('Conversion warnings:', result.warnings);\n  }\n};\n```\n\n</Steps>\n\n## Export DOCX\n\n<Steps>\n\n### Basic Export\n\nUse `exportToDocx` to convert Plate content to a DOCX file:\n\n```tsx\nimport { exportToDocx, downloadDocx } from '@platejs/docx-io';\n\nconst handleExport = async () => {\n  const blob = await exportToDocx(editor.children, {\n    orientation: 'portrait',\n    margins: { top: 1440, bottom: 1440, left: 1440, right: 1440 },\n    fontFamily: 'Calibri',\n  });\n\n  downloadDocx(blob, 'document.docx');\n};\n```\n\nOr use the combined function:\n\n```tsx\nimport { exportEditorToDocx } from '@platejs/docx-io';\n\nawait exportEditorToDocx(editor.children, 'document', {\n  orientation: 'portrait',\n});\n```\n\n### With Editor Plugins\n\nFor accurate serialization, provide your editor plugins:\n\n```tsx\nimport { exportToDocx } from '@platejs/docx-io';\nimport { BaseEditorKit } from '@/components/editor/editor-base-kit';\nimport { DocxExportKit } from '@/components/editor/plugins/docx-export-kit';\n\nconst blob = await exportToDocx(editor.children, {\n  editorPlugins: [...BaseEditorKit, ...DocxExportKit],\n});\n```\n\n### Custom Styles\n\nCustomize the export styles:\n\n```tsx\nimport { exportToDocx, DOCX_EXPORT_STYLES } from '@platejs/docx-io';\n\nconst blob = await exportToDocx(editor.children, {\n  customStyles: `\n    .custom-highlight { background-color: #ffeb3b; }\n    h1 { color: #1a1a1a; }\n  `,\n  fontFamily: 'Times New Roman',\n});\n```\n\n### Using DocxExportPlugin\n\nFor plugin-based API access:\n\n```tsx\nimport { DocxExportPlugin } from '@platejs/docx-io';\nimport { createPlateEditor } from 'platejs/react';\n\nconst editor = createPlateEditor({\n  plugins: [\n    // ...otherPlugins,\n    DocxExportPlugin.configure({\n      options: {\n        editorPlugins: myPlugins,\n        editorStaticComponent: MyEditorStatic,\n      },\n    }),\n  ],\n});\n\n// Export using plugin API\nconst blob = await editor.api.docxExport.exportToBlob({\n  orientation: 'landscape',\n});\n\neditor.api.docxExport.download(blob, 'document');\n\n// Or use transform for export + download\nawait editor.tf.docxExport.exportAndDownload('document', {\n  orientation: 'portrait',\n});\n```\n\n</Steps>\n\n## DOCX Export Kit\n\nThe `DocxExportKit` provides DOCX-optimized static components for elements that require special handling:\n\n<ComponentSource name=\"docx-export-kit\" />\n\nComponents included:\n- **Code blocks**: Inline syntax highlighting with line breaks\n- **Columns**: Table layout instead of flexbox\n- **Equations**: Inline font styling (KaTeX doesn't work in DOCX)\n- **Callouts**: Table layout for icon + content\n- **TOC**: Anchor links with proper paragraph breaks\n\n## Plugins\n\n### DocxExportPlugin\n\nPlugin providing DOCX export functionality with typed API methods.\n\n<API name=\"DocxExportPlugin\">\n<APIOptions>\n<APIItem name=\"editorPlugins\" type=\"SlatePlugin[]\" optional>\nPlugins to use for HTML serialization. If not provided, uses the editor's current plugins.\n</APIItem>\n<APIItem name=\"editorStaticComponent\" type=\"React.ComponentType<PlateStaticProps>\" optional>\nReact component to use for static rendering.\n</APIItem>\n</APIOptions>\n</API>\n\n## API\n\n### `importDocx`\n\nImport a DOCX file and convert it to Plate nodes.\n\n<API name=\"importDocx\">\n<APIParameters>\n<APIItem name=\"editor\" type=\"SlateEditor\">\nThe Plate editor instance.\n</APIItem>\n<APIItem name=\"arrayBuffer\" type=\"ArrayBuffer\">\nThe DOCX file as ArrayBuffer.\n</APIItem>\n<APIItem name=\"options\" type=\"ImportDocxOptions\" optional>\nImport options.\n</APIItem>\n</APIParameters>\n\n<APIOptions type=\"ImportDocxOptions\">\n<APIItem name=\"rtf\" type=\"string\" optional>\nRTF data for image extraction.\n</APIItem>\n</APIOptions>\n\n<APIReturns type=\"Promise<ImportDocxResult>\">\n<APIItem name=\"nodes\" type=\"TNode[]\">\nDeserialized editor nodes.\n</APIItem>\n<APIItem name=\"comments\" type=\"DocxComment[]\">\nComments extracted from the DOCX file.\n</APIItem>\n<APIItem name=\"warnings\" type=\"string[]\">\nWarnings from mammoth conversion.\n</APIItem>\n</APIReturns>\n</API>\n\n### `exportToDocx`\n\nConvert Plate content to a DOCX blob.\n\n<API name=\"exportToDocx\">\n<APIParameters>\n<APIItem name=\"value\" type=\"Value\">\nThe Plate editor value (array of nodes).\n</APIItem>\n<APIItem name=\"options\" type=\"DocxExportOptions\" optional>\nExport options.\n</APIItem>\n</APIParameters>\n\n<APIOptions type=\"DocxExportOptions\">\n<APIItem name=\"orientation\" type=\"'portrait' | 'landscape'\" optional>\nPage orientation.\n\n- **Default:** `'portrait'`\n</APIItem>\n<APIItem name=\"margins\" type=\"DocxExportMargins\" optional>\nPage margins in twentieths of a point (1 inch = 1440).\n\n- **Default:** `{ top: 1440, bottom: 1440, left: 1440, right: 1440, header: 720, footer: 720, gutter: 0 }`\n</APIItem>\n<APIItem name=\"fontFamily\" type=\"string\" optional>\nFont family for the document body. Overrides default Calibri font.\n</APIItem>\n<APIItem name=\"customStyles\" type=\"string\" optional>\nAdditional CSS styles to include. Appended after default DOCX_EXPORT_STYLES.\n</APIItem>\n<APIItem name=\"title\" type=\"string\" optional>\nDocument title for metadata.\n</APIItem>\n<APIItem name=\"editorPlugins\" type=\"SlatePlugin[]\" optional>\nPlugins for HTML serialization.\n</APIItem>\n<APIItem name=\"editorStaticComponent\" type=\"React.ComponentType\" optional>\nComponent for static rendering.\n</APIItem>\n</APIOptions>\n\n<APIReturns type=\"Promise<Blob>\">\nA Blob containing the DOCX file.\n</APIReturns>\n</API>\n\n### `downloadDocx`\n\nDownload a DOCX blob as a file.\n\n<API name=\"downloadDocx\">\n<APIParameters>\n<APIItem name=\"blob\" type=\"Blob\">\nThe DOCX blob to download.\n</APIItem>\n<APIItem name=\"filename\" type=\"string\">\nThe filename (with or without .docx extension).\n</APIItem>\n</APIParameters>\n</API>\n\n### `exportEditorToDocx`\n\nExport and download editor content as a DOCX file in one call.\n\n<API name=\"exportEditorToDocx\">\n<APIParameters>\n<APIItem name=\"value\" type=\"Value\">\nThe Plate editor value.\n</APIItem>\n<APIItem name=\"filename\" type=\"string\">\nThe filename for download.\n</APIItem>\n<APIItem name=\"options\" type=\"DocxExportOptions\" optional>\nExport options (same as `exportToDocx`).\n</APIItem>\n</APIParameters>\n</API>\n\n### api.docxExport.exportToBlob\n\nConvert editor content to a DOCX blob using the plugin API.\n\n<API name=\"api.docxExport.exportToBlob\">\n<APIOptions type=\"DocxExportOperationOptions\">\n<APIItem name=\"orientation\" type=\"'portrait' | 'landscape'\" optional>\nPage orientation.\n</APIItem>\n<APIItem name=\"margins\" type=\"DocxExportMargins\" optional>\nPage margins.\n</APIItem>\n<APIItem name=\"fontFamily\" type=\"string\" optional>\nFont family.\n</APIItem>\n<APIItem name=\"customStyles\" type=\"string\" optional>\nAdditional CSS styles.\n</APIItem>\n<APIItem name=\"title\" type=\"string\" optional>\nDocument title.\n</APIItem>\n</APIOptions>\n\n<APIReturns type=\"Promise<Blob>\">\nA Blob containing the DOCX file.\n</APIReturns>\n</API>\n\n### api.docxExport.download\n\nDownload a DOCX blob as a file.\n\n<API name=\"api.docxExport.download\">\n<APIParameters>\n<APIItem name=\"blob\" type=\"Blob\">\nThe DOCX blob.\n</APIItem>\n<APIItem name=\"filename\" type=\"string\">\nThe filename.\n</APIItem>\n</APIParameters>\n</API>\n\n## Transforms\n\n### tf.docxExport.exportAndDownload\n\nExport and download editor content as a DOCX file.\n\n<API name=\"tf.docxExport.exportAndDownload\">\n<APIParameters>\n<APIItem name=\"filename\" type=\"string\">\nThe filename for download.\n</APIItem>\n<APIItem name=\"options\" type=\"DocxExportOperationOptions\" optional>\nExport options.\n</APIItem>\n</APIParameters>\n</API>\n\n## Types\n\n### DocxComment\n\n```ts\ntype DocxComment = {\n  id: string;\n  text: string;\n};\n```\n\n### DocxExportMargins\n\n```ts\ntype DocxExportMargins = {\n  top?: number;\n  bottom?: number;\n  left?: number;\n  right?: number;\n  header?: number;\n  footer?: number;\n  gutter?: number;\n};\n```\n\n## Constants\n\n### DOCX_EXPORT_STYLES\n\nDefault CSS styles optimized for Microsoft Word HTML rendering:\n\n- Calibri font (Microsoft Office default)\n- 11pt font size with 1.5 line height\n- Heading hierarchy (24pt to 10pt)\n- Table styles with borders\n- Code block styling with Courier New\n- Blockquote styling with left border\n\n## Known Limitations\n\n- **Mobile browsers**: Export may not work reliably on mobile browsers due to limitations with blob handling and downloads.\n- **Complex layouts**: Some complex CSS layouts (flexbox, grid) are converted to table-based layouts for Word compatibility.\n- **Custom fonts**: Only system fonts available in Word will render correctly.\n",
      "type": "registry:file",
      "target": "content/docs/plate/(plugins)/(serializing)/docx-io.mdx"
    }
  ],
  "type": "registry:file"
}