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

    Module @microscope-js/renderer-text

    @microscope-js/renderer-text

    npm Bundle Types Provenance

    Plain-text / source-code renderer for microscope-js. Content is set with textContent, never innerHTML — XSS-safe by construction. Recognizes every common source-code extension out of the box.

    pnpm add @microscope-js/renderer-text
    
    import { createRegistry, mount } from '@microscope-js/core';
    import { textRenderer } from '@microscope-js/renderer-text';

    const registry = createRegistry([textRenderer]);
    await mount({
    source: file,
    container,
    registry,
    options: { maxBytes: 4 * 1024 * 1024, encoding: 'utf-8' },
    });
    Option Default Description
    maxBytes 8 * 1024 * 1024 Reject files larger than this (MicroscopeError('TOO_LARGE'))
    encoding 'utf-8' Override TextDecoder encoding — accepts any IANA name your runtime supports

    Plain text (text/*) plus JSON, XML, YAML, and most source-code extensions:

    txt md markdown log csv tsv json jsonl xml yaml yml
    js mjs cjs ts tsx jsx css scss html htm
    go rs py rb java kt swift c cc cpp h hpp
    sh bash zsh ini toml env

    Don't see your extension? Pass rendererId: 'text' to mount() / <Viewer /> to force-pick this renderer.

    • The decoded text is assigned via element.textContent — HTML in the source is never parsed. No DOMPurify needed because no HTML exists in the first place.
    • Files over maxBytes are rejected before decoding to prevent OOM.
    • TextDecoder is constructed with fatal: false so a malformed sequence shows replacement characters instead of throwing.

    MIT

    Interfaces

    TextOptions

    Variables

    textRenderer

    References

    default → textRenderer