| 2464 | // none; the rest is copied in runs between escapes. Invalid characters are |
| 2465 | // kept, so that the writer can check them in the output. |
| 2466 | const escapeText = (s: string): string => { |
| 2467 | const first = s.search(textSpecial) |
| 2468 | if (first === -1) return s |
| 2469 | let out = "" |
| 2470 | let last = 0 |
| 2471 | for (let i = first; i < s.length; i++) { |
| 2472 | const c = s.charCodeAt(i) |
| 2473 | const escaped = c === AMPERSAND ? "&" : c === LT ? "<" : c === GT ? ">" : c === CR ? " " : undefined |
| 2474 | if (escaped !== undefined) { |
| 2475 | out += s.slice(last, i) + escaped |
| 2476 | last = i + 1 |
| 2477 | } |
| 2478 | } |
| 2479 | return out + s.slice(last) |
| 2480 | } |
| 2481 | |
| 2482 | const escapeAttribute = (s: string): string => { |
| 2483 | const first = s.search(attributeSpecials) |