Styling and Components
The library emits stable wtr-* classes and a set of CSS variables. Page structure, labels, heading anchors, and component appearance can all be adjusted without patching the library.
Styles
Import the page stylesheet once:
- The library sets no global element styles; page typography inherits from the host.
- The root container is
div.wtr-view; library classes start withwtr-and some MediaWiki compatibility classes are preserved. - Inline styles keep only whitelisted layout and appearance declarations; unsafe values are dropped whole. Under strict CSP, allow
style-srcas needed.
CSS variables
Variables are defined on :root and can be overridden on any ancestor:
Dark themes can override the same variables through [data-wtr-theme="dark"] or the host's own selector.
Container props
className and containerProps.className merge with wtr-view. The containerProps type excludes dangerouslySetInnerHTML.
Labels
All user-visible placeholders and notices come from labels. Prepare options accept Partial<WikitextLabels>; omitted fields keep the default English strings.
The effective labels are written to WikitextRenderDocument.meta.labels; the view and components read the same strings.
Heading anchors
- Anchors are generated from stripped heading text: whitespace becomes
_, duplicate ids get_2/_3case-insensitively, and empty headings fall back tosection-{n}. - Semantic headings and source
h1–h6both participate. idPrefixapplies only toinstance; without it, the view uses a ReactuseIdprefix.- The view maps heading
id, in-document#fragmentlinks, and tableheadersattributes.
Read the final heading list from the render snapshot:
Component overrides
Overrides have the following precedence:
semanticComponents[type]replaces the whole wiki semantic structure.components[tag]replaces an HTML tag inside the default HAST structure.- Native elements.
HTML components
components maps by HAST tag name such as p, table, img, or a. Components receive sanitized DOM props, the HAST node, the document, and optionally the semantic node and origin. Do not spread non-DOM props onto native elements.
Semantic components
Available semantic types:
semanticComponents.extensionreceives all extension nodes exceptref;refusesreference, and<references>produces no component call.semanticComponents.referencereplaces only the<sup>; the endnotes section is still generated by the library.WikitextFragmentmust run inside theWikitextViewcontext, andnodesmust be the same node objects from the current render document. It is intended for children the default renderer does not output, such as template parameters, file captions, andrefcontent.
components and semanticComponents are trusted code; HTML they emit is not sanitized again. Resolver URLs are validated during preparation, but components should still avoid putting untrusted input into dangerous attributes.
Read the context
useWikitextContext()providesdocument, indexes, component maps,idPrefix,mapId,mapHref, andonRenderError.useWikitextLabels()reads labels from the current render snapshot.useWikitextIds()providestoDomIdandtoHref.
These hooks and WikitextFragment must be used inside <WikitextView>.
Plugins
wikitextPluginsrun on the cloned semantic tree;rehypePluginsrun after HAST conversion and before final sanitization.- The plugin signature follows unified's
(tree, file), wherefileis a VFile. - The original parse snapshot is not modified; preparation reassigns ids on the working tree.
- The synchronous entry rejects async plugins; use
prepareWikitextAsyncfor those. - Final sanitization always runs after rehype plugins; plugins cannot bypass whitelists or image authorization.
Plugin lists are structured arrays. Elements can be plugin functions or [plugin, options] tuples and run in order.
Security policy
prepareOptions.policy adjusts URL and tag whitelists. Defaults:
policy is shallow-merged with defaults; array fields are replaced wholesale. class is filtered only by the [A-Za-z0-9_-] safe character set, with no option to widen or narrow it. For tags, attributes, or rich presentation outside the whitelist, prefer /view component overrides; do not loosen sanitization.
Custom semantic nodes
Custom nodes require extending WikitextNodeMap and registering a HAST converter in prepareOptions.handlers. A node without a handler produces a diagnostic and degrades to a source card. Handler context, budgets, and conversion details are in the prepare API.