(s: string, i: number)
| 2105 | } |
| 2106 | |
| 2107 | private doctypeDeclaration(s: string, i: number): number { |
| 2108 | if (this.state !== PROLOG || this.doctype) { |
| 2109 | throw this.syntax("a DOCTYPE is only allowed once, before the root element", i) |
| 2110 | } |
| 2111 | const scanner = new Scanner() |
| 2112 | scanner.reset(S_DOCTYPE) |
| 2113 | const end = scanner.scan(s, i + 9) |
| 2114 | if (end === -1) return -1 |
| 2115 | this.checkSize(i, end) |
| 2116 | this.doctype = true |
| 2117 | let j = this.space(s, i + 9, end) |
| 2118 | const nameEnd = this.name(s, j, end) |
| 2119 | const event: { -readonly [K in keyof Doctype]: Doctype[K] } = { _tag: "Doctype", name: s.slice(j, nameEnd) } |
| 2120 | j = skipSpace(s, nameEnd, end) |
| 2121 | if (j > nameEnd && (s.startsWith("PUBLIC", j) || s.startsWith("SYSTEM", j))) { |
| 2122 | if (s.charCodeAt(j) === 80) { |
| 2123 | // Whitespace in public identifiers is normalized for matching |
| 2124 | event.publicId = this.publicLiteral(s, this.space(s, j + 6, end), end).replace(publicIdWhitespace, " ").trim() |
| 2125 | j = this.literalEnd |
| 2126 | } |
| 2127 | event.systemId = normalizeLines( |
| 2128 | this.literal(s, this.space(s, j + (event.publicId === undefined ? 6 : 0), end), end) |
| 2129 | ) |
| 2130 | j = skipSpace(s, this.literalEnd, end) |
| 2131 | } |
| 2132 | if (s.charCodeAt(j) === LBRACKET) { |
| 2133 | // The scanner skips the internal subset, whose declarations are not |
| 2134 | // checked, and ends the token early only at malformed markup |
| 2135 | if (scanner.state !== S_AFTER_SUBSET) throw this.syntax("invalid markup in the internal subset", end) |
| 2136 | j = skipSpace(s, s.lastIndexOf("]", end - 1) + 1, end) |
| 2137 | } |
| 2138 | if (j !== end - 1 || s.charCodeAt(j) !== GT) throw this.syntax("invalid DOCTYPE", j) |
| 2139 | this.out.push(event) |
| 2140 | return end |
| 2141 | } |
| 2142 | |
| 2143 | // Skips the whitespace that is required at `i` |
| 2144 | private space(s: string, i: number, end: number): number { |
no test coverage detected