svelte_preprocess_helpers.ts view source
(text: string): string import {escape_svelte_text} from '@fuzdev/fuz_util/svelte_preprocess_helpers.js'; Escapes text for safe embedding in Svelte template markup.
Uses a single-pass regex replacement to avoid corruption that occurs with sequential
.replace() calls (where the second replace matches characters introduced by the first).
Escapes four characters:
- { → {'{'} and } → {'}'} — prevents Svelte expression interpretation
- < → < — prevents HTML/Svelte tag interpretation
- & → & — prevents HTML entity interpretation
The & escaping is necessary because runtime MdzNodeView.svelte renders text
with {node.content} (a Svelte expression), which auto-escapes & to &.
The preprocessor emits raw template text where & is NOT auto-escaped, so
manual escaping is required to match the runtime behavior.