(raw: string, amp: number, semicolon: number, offset: number)
| 1651 | |
| 1652 | // Decodes the reference `raw[amp, semicolon]` |
| 1653 | private reference(raw: string, amp: number, semicolon: number, offset: number): string { |
| 1654 | const c = raw.charCodeAt(amp + 1) |
| 1655 | // The predefined entities, without slicing their names |
| 1656 | if (c === 97) { |
| 1657 | if (raw.startsWith("amp;", amp + 1)) return "&" |
| 1658 | if (raw.startsWith("apos;", amp + 1)) return "'" |
| 1659 | } else if (c === 108) { |
| 1660 | if (raw.startsWith("lt;", amp + 1)) return "<" |
| 1661 | } else if (c === 103) { |
| 1662 | if (raw.startsWith("gt;", amp + 1)) return ">" |
| 1663 | } else if (c === 113) { |
| 1664 | if (raw.startsWith("quot;", amp + 1)) return "\"" |
| 1665 | } |
| 1666 | if (c === HASH) { |
| 1667 | const hex = raw.charCodeAt(amp + 2) === LOWER_X |
| 1668 | const digits = raw.slice(amp + (hex ? 3 : 2), semicolon) |
| 1669 | const code = (hex ? hexDigits : decimalDigits).test(digits) ? parseInt(digits, hex ? 16 : 10) : -1 |
| 1670 | if (!isChar(code)) throw this.syntax("invalid character reference", offset + amp) |
| 1671 | return String.fromCodePoint(code) |
| 1672 | } |
| 1673 | const name = raw.slice(amp + 1, semicolon) |
| 1674 | if (!isName(name)) throw this.syntax("invalid reference", offset + amp) |
| 1675 | if (this.doctype) { |
| 1676 | throw this.error( |
| 1677 | "Unsupported", |
| 1678 | `entity references other than the predefined entities are not supported: &${name};`, |
| 1679 | this.base + offset + amp |
| 1680 | ) |
| 1681 | } |
| 1682 | throw this.syntax(`undefined entity &${name};`, offset + amp) |
| 1683 | } |
| 1684 | |
| 1685 | // Parses the markup at `i`, and returns its end or -1 when it is incomplete |
| 1686 | private markup(s: string, i: number): number { |
no test coverage detected