Skip to main content

@docxio/html

HTML and Markdown export for docxio document trees.

Installation​

npm install @docxio/html

Size: ~5 KB

API​

renderToHtml​

Converts a docxio document tree to an HTML string.

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

const html = renderToHtml(doc);

Headings map to <h1>-<h6>, paragraphs to <p>, bold runs to <strong>, italic to <em>, tables to <table>, lists to <ul>/<ol>, hyperlinks to <a>, and images to <img>.

renderToMarkdown​

Converts a docxio document tree to a Markdown string.

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

const md = renderToMarkdown(doc);

Headings map to # syntax, bold to **text**, italic to *text*, tables to pipe tables, lists to - or 1. , hyperlinks to [text](url), and images to ![alt](src).

Example​

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

const doc = (
<document>
<section>
<heading level={1}><run>Report</run></heading>
<paragraph>
<run>Total: </run>
<run bold>$1.2M</run>
</paragraph>
</section>
</document>
);

console.log(renderToHtml(doc));
// <h1>Report</h1><p>Total: <strong>$1.2M</strong></p>

console.log(renderToMarkdown(doc));
// # Report\n\nTotal: **$1.2M**

Limitations​

  • Complex formatting (character spacing, emboss, imprint) is not represented in HTML/Markdown
  • Floating image positions are not preserved
  • Page breaks and section properties are ignored (HTML/Markdown are flow-based)