import { classApplier, core, highlighter, saveStore, serializer, textRange, } from "./rangy@1.3.2"; import { BridgingNames, HISTORY_LIMIT } from "./types"; import type { Highlighter, AnimationOptions, CSSString, HTMLString, HighlighterOptions, Highlights, SelectableTextViewFonts, SelectableTextViewOptions, GoogleFontFamily, } from "./types"; export function escapeHtmlAttribute(value: string): string { return value .replace(/&/g, "&") .replace(/"/g, """) .replace(/'/g, "'") .replace(//g, ">"); } // U+2028/U+2029 are valid inside a JSON string but were line terminators in // JS before ES2019. The pattern is built at runtime because neither form // survives well in a regex literal: the raw character IS a line terminator, // which makes the literal a syntax error. const JS_LINE_SEPARATORS = new RegExp( String.fromCharCode(0x2028) + "|" + String.fromCharCode(0x2029), "g" ); /** * Serializes a value for interpolation into the injected `/g, "\\u003E") .replace(JS_LINE_SEPARATORS, (char) => char === String.fromCharCode(0x2028) ? "\\u2028" : "\\u2029" ); } /** * Escapes a value for use inside a double-quoted CSS string, e.g. `url("…")`. * * HTML-entity escaping is wrong in this position: `
${content}