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.
pnpm add @microscope-js/renderer-docx
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 }}
/>
| 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 |
.docx (Word 2007+) — primary target, well supported by mammoth.doc (legacy binary) — best-effort; mammoth has limited coverage of the older format@microscope-js/utils — script, iframe, form, every on* attribute, data: URIs (except safe image types), and unknown protocols are stripped.rel="noopener noreferrer" + target="_blank".@microscope-js/renderer-xlsx · @microscope-js/renderer-pptx — the other Office formats@microscope-js/react — React adapter