node-docx-html-converter
v0.1.0
Published
Convert DOCX ↔ HTML using Rust WASM. Two functions: docxToHtml and htmlToDocx.
Readme
node-docx-html-converter
DOCX ↔ HTML conversion via Rust WASM. Two main functions:
- docxToHtml — DOCX bytes → HTML string
- htmlToDocx — HTML string → DOCX bytes
Install
npm install node-docx-html-converterUsage
ESM (sync)
import { docxToHtml, htmlToDocx } from 'node-docx-html-converter';
import fs from 'fs';
// DOCX → HTML
const docxBuffer = fs.readFileSync('document.docx');
const html = docxToHtml(docxBuffer);
// or embeddable fragment:
const embed = docxToHtml(docxBuffer, { embed: true });
// HTML → DOCX
const htmlStr = fs.readFileSync('output.html', 'utf8');
const docxBytes = htmlToDocx(htmlStr);
fs.writeFileSync('output.docx', docxBytes);CommonJS (sync)
const { docxToHtml, htmlToDocx } = require('node-docx-html-converter');
const html = docxToHtml(docxBuffer);
const docxBytes = htmlToDocx(htmlStr);API
docxToHtml(docxBuffer, options?)
docxBuffer—BufferorUint8Arraywith .docx file bytesoptions.embed— if true, returns embeddable fragment (no DOCTYPE)options.noH4— when true, bold from paragraph style not applied to list itemsoptions.debugLayout— when true, adds colored borders for debugging- Returns:
string
htmlToDocx(html)
html— HTML string (full document or embed fragment from docx-html-converter)- Returns:
Buffer
calculate_html(html)
Recalculates page breaks for contentEditable. Returns reflowed HTML.
