@microscope-js/renderer-text
v0.1.5
Published
Plain text / source-code renderer for microscope-js
Readme
@microscope-js/renderer-text
Plain-text / source-code renderer for microscope-js. Content is set with
textContent, neverinnerHTML— XSS-safe by construction. Recognizes every common source-code extension out of the box.
Install
pnpm add @microscope-js/renderer-textUse
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' },
});Options
| 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 |
Format support
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 envDon't see your extension? Pass rendererId: 'text' to mount() / <Viewer /> to force-pick this renderer.
Security model
- 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
maxBytesare rejected before decoding to prevent OOM. TextDecoderis constructed withfatal: falseso a malformed sequence shows replacement characters instead of throwing.
See also
@microscope-js/react— React adapter- Repository · Live demo · API docs
