microscope-js - v0.0.0
    Preparing search index...

    Module @microscope-js/renderer-docx

    @microscope-js/renderer-docx

    npm Bundle Types Provenance

    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
    • Every HTML node mammoth emits is sanitized via the shared DOMPurify profile from @microscope-js/utils — script, iframe, form, every on* 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.

    MIT

    Interfaces

    DocxOptions

    Variables

    docxRenderer

    References

    default → docxRenderer