@docx-editor.dev/docx-to-markdown

中文文档
2.37.0发布于 2026/11/11Apache-2.0TypeScriptESM + CJS构建来源已验证近 30 天下载 9273

Convert DOCX to Markdown with layout-derived pages, headers, footers, comments, and tracked changes.

原始使用文档
文档目录9 节
  1. Before you begin
  2. Install the package
  3. Convert a DOCX file
  4. Include images
  5. Preserve displayed image sizes
  6. Read page output
  7. Configure fonts for accurate layout
  8. Runtime and output
  9. Next steps

DOCX Editor by EigenPal

DOCX to Markdown

Use @docx-editor.dev/docx-to-markdown to convert DOCX files to Markdown. The result includes the body, pages, headers, footers, comments, and tracked changes.

Try the DOCX to Markdown demo or read the Markdown export guide.

Before you begin

For Node.js, use version 20.16.0 or later in the 20.x release line, or version 22.3.0 or later. The converter requires WebAssembly and uses bundled fonts by default.

Install the package

npm install @docx-editor.dev/docx-to-markdown @docx-editor.dev/core

@docx-editor.dev/core is a required peer dependency. Install a version that satisfies the converter's peer dependency range and commit your lockfile.

Convert a DOCX file

The following example reads a local file in Node.js:

import { readFile } from 'node:fs/promises';
import { exportMarkdown } from '@docx-editor.dev/docx-to-markdown';

const docxBytes = await readFile('document.docx');
const result = await exportMarkdown(docxBytes);
console.log(result.markdown);

Include images

Set images: true to include image links and extracted bytes:

const result = await exportMarkdown(docxBytes, { images: true });

result.media contains image bytes and their page occurrences. See image workflows to save a folder, download a ZIP, or return hosted URLs.

Preserve displayed image sizes

Use images: { syntax: 'html' } to include displayed sizes in generated <img> tags. Dimensions use whole CSS pixels. Configure your renderer to allow sanitized HTML and retain width and height. The default Markdown syntax has no size attributes.

For custom previews, use displayWidthPx and displayHeightPx. Asset pixelWidth and pixelHeight describe the image file. The converter omits crop, rotation, and floating text wrapping. See Preserve displayed image sizes.

Read page output

The document layout engine calculates page breaks.

for (const page of result.pages) {
  console.log(page.number, page.markdown);
  console.log(page.headerMarkdown, page.footerMarkdown);
}

result.markdown contains continuous document text without page separators. Use it for an unpaged .md download. Headers and footers stay in result.pages.

For search and AI ingestion, use { displayMode: 'proposed' } to show pending insertions and hide pending deletions. The default, 'all-markup', shows both.

Configure fonts for accurate layout

Fonts determine line wrapping, table row heights, and the page boundaries in result.pages. Markdown does not preserve the DOCX font family, but the converter needs font measurements to calculate layout.

Start with the bundled substitutes for common document fonts. Use fonts to supply the author's licensed fonts or override a substitute. Use fallbackFonts: googleFonts() to load missing faces from Google Fonts; it requires network access and does not override faces already resolved by earlier sources.

See font setup and troubleshooting for runnable examples, resolution reports, and guidance on matching page references to the source document.

Runtime and output

For Next.js, use the Node.js runtime and server package configuration. Edge runtimes are not supported.

Page breaks depend on fonts, document features, and revision mode; they can differ from the application that created the document. Store the document version with page citations. result.warnings reports omitted content and font problems. Images are omitted unless enabled. See output limits before using the output as a complete transcription.

The package uses the Apache 2.0 license, including comment and tracked-change extraction. Bundled fonts retain their own open-source licenses.

Next steps

版本与发布记录

@docx-editor.dev/docx-to-markdown 共发布 30 个版本,首次发布于 2026/09/15;过去 12 个月发布了 30 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
2.37.0latest2026/11/112 天前
2.37.0-canary.20261111032756.sha-9eef508canary2026/11/112 天前
2.37.0-canary.20261110032710.sha-525df6f2026/11/103 天前
2.36.02026/11/094 天前
2.36.0-canary.20261108032737.sha-f189d652026/11/085 天前
2.35.1-canary.20261107032606.sha-f3116762026/11/076 天前

关于 @docx-editor.dev/docx-to-markdown 的常见问题

@docx-editor.dev/docx-to-markdown 是什么?

Convert DOCX to Markdown with layout-derived pages, headers, footers, comments, and tracked changes.

如何安装 @docx-editor.dev/docx-to-markdown?

在项目目录运行 npm install @docx-editor.dev/docx-to-markdown,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:@docx-editor.dev/core(~2.37.0)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@docx-editor.dev/docx-to-markdown 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@docx-editor.dev/docx-to-markdown 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@docx-editor.dev/docx-to-markdown 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js ^20.16.0 || >=22.3.0。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@docx-editor.dev/docx-to-markdown 可以商用吗?

@docx-editor.dev/docx-to-markdown 使用 Apache-2.0 许可。宽松许可:允许商业使用、修改和再分发,并附带明确的专利授权;分发时需保留许可与 NOTICE 文件,修改过的文件要注明改动。以上为概括,不构成法律意见,请以许可原文为准。

@docx-editor.dev/docx-to-markdown 的下载量有多少?

根据 npm 官方下载统计,@docx-editor.dev/docx-to-markdown 在 2026/10/13 – 2026/11/11 这 30 天内被下载 9,273 次,日均约 309 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@docx-editor.dev/docx-to-markdown 还在维护吗?

最新版本 2.37.0 发布于 2026/11/11(2 天前);至今共发布 30 个版本,其中过去 12 个月发布了 30 个;首次发布于 2026/09/15。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。