Skip to main content

HTML and Markdown Export

The @docxio/html package converts docxio document trees to HTML or Markdown strings. This is useful for previews, email bodies, or static site content.

Installation​

npm install @docxio/html

Render to HTML​

/** @jsxImportSource docxio */
import { renderToHtml } from "@docxio/html";

const doc = (
<document>
<section>
<heading level={1}><run>Title</run></heading>
<paragraph>
<run>Regular text with </run>
<run bold>bold</run>
<run> and </run>
<run italic>italic</run>
</paragraph>
<table>
<row>
<cell><paragraph><run>A</run></paragraph></cell>
<cell><paragraph><run>B</run></paragraph></cell>
</row>
</table>
</section>
</document>
);

const html = renderToHtml(doc);

Output:

<h1>Title</h1>
<p>Regular text with <strong>bold</strong> and <em>italic</em></p>
<table><tr><td>A</td><td>B</td></tr></table>

Render to Markdown​

import { renderToMarkdown } from "@docxio/html";

const markdown = renderToMarkdown(doc);

Output:

# Title

Regular text with **bold** and *italic*

| A | B |
|---|---|

Element mapping​

docxio elementHTML outputMarkdown output
<heading level={N}><hN># to ######
<paragraph><p>Plain text + newline
<run bold><strong>**text**
<run italic><em>*text*
<run underline><u>Plain text
<table><table>Pipe table
<hyperlink><a href>[text](url)
<image><img>![alt](src)
<bullet-list><ul>- item
<numbered-list><ol>1. item

Use cases​

  • Email previews -- convert a docxio document to HTML for email body content
  • Static site generation -- export document content as Markdown for CMS integration
  • Testing -- compare HTML output in snapshot tests for easier visual diffing

See also the render API reference for all render function signatures.