@microscope-js/renderer-docx
v0.1.5
Published
DOCX (Word) renderer for microscope-js (uses mammoth + DOMPurify)
Readme
@microscope-js/renderer-docx
Renders
.docx(Word) documents in the browser for microscope-js, via mammoth.js. The HTML mammoth produces is run through a hardened DOMPurify profile before it ever touches the DOM.
Install
pnpm add @microscope-js/renderer-docxUse
import { createRegistry, mount } from '@microscope-js/core';
import { docxRenderer } from '@microscope-js/renderer-docx';
const registry = createRegistry([docxRenderer]);
await mount({ source: file, container, registry });Or with React:
<Viewer
source={file}
registry={useRegistry([docxRenderer])}
options={{ maxBytes: 32 * 1024 * 1024 }}
/>Options
| Option | Default | Description |
| ----------- | ------------------ | -------------------------------------------------------------------------- |
| maxBytes | 64 * 1024 * 1024 | Reject docx files larger than this (MicroscopeError('TOO_LARGE')) |
| styleMap | mammoth defaults | Custom style map — map Word styles to HTML elements |
Format support
.docx(Word 2007+) — primary target, well supported by mammoth.doc(legacy binary) — best-effort; mammoth has limited coverage of the older format
Security model
- Every HTML node mammoth emits is sanitized via the shared DOMPurify profile from
@microscope-js/utils—script,iframe,form, everyon*attribute,data:URIs (except safe image types), and unknown protocols are stripped. - All anchors are rewritten to
rel="noopener noreferrer"+target="_blank". - The size cap defends against zip-bomb-class inputs.
- mammoth + this renderer run only in the user's browser. The document never leaves the tab.
See also
@microscope-js/renderer-xlsx·@microscope-js/renderer-pptx— the other Office formats@microscope-js/react— React adapter- Repository · Live demo · API docs
