wordml-preview
v0.1.1
Published
Render Word 2003 XML (WordprocessingML) into HTML, in the browser. No dependencies.
Maintainers
Readme
wordml-preview
Render Word 2003 XML (WordprocessingML) documents into HTML, in the browser.
Word's "Word 2003 XML Document" format is flat XML, not a zip archive, so
docx-preview and
mammoth - both OOXML/JSZip based - cannot read it.
This library can. No runtime dependencies: it uses DOMParser and plain DOM APIs.
Install
npm install wordml-previewUsage
The stylesheet ships as a separate file - import it once, anywhere in your app:
import { renderWordML } from 'wordml-preview';
import 'wordml-preview/style.css';
const xml = await file.text();
const stats = renderWordML(xml, document.getElementById('viewer'), { paginate: true });renderWordML(input, container, options?) is synchronous. input takes the raw XML as a
string, ArrayBuffer or typed array; container is emptied and filled with the rendered
pages.
| Option | Default | Effect |
| --- | --- | --- |
| paginate | true | Reflow the content into fixed-size page elements. false renders one long page. |
| floatImages | true | Honour VML absolute positioning for floating pictures. |
The returned stats carry pages, the page metrics, counts of what was rendered, and
unhandled - the WordML elements this version does not support. Unsupported input is
recorded there rather than thrown, so a document always renders as far as it can.
Page size and print rules depend on the document's own w:sectPr, so a small @page style
tag is injected into <head> on each render. Everything else lives in the imported CSS.
Development
npm install
npm run dev # vite dev server, opens demo/ with a sample document
npm run watch # vite build --watch
npm run build # tsc -b && vite build -> dist/
npm run type-check
npm run lint
npm run formatNode version is pinned in .nvmrc.
demo/ is the manual test harness: it renders demo/sample.xml (which exercises styles,
nested lists, tab stops, merged table cells, a page break, footers and PAGE/NUMPAGES fields)
and prints the render stats in the header bar. Drop your own .xml on the file picker to
check a real document. It is not part of the published package.
