|
28 | 28 | * Way too simple, but works for us.
|
29 | 29 | * @property {HiddenPreprocessor} preprocessor
|
30 | 30 | * @property {(value: string) => void} write
|
| 31 | + * @property {() => number} _consume |
31 | 32 | * @property {Array.<HiddenToken>} tokenQueue
|
32 | 33 | * @property {string} state
|
33 | 34 | * @property {string} returnState
|
34 | 35 | * @property {number} charRefCode
|
35 | 36 | * @property {Array.<number>} tempBuff
|
| 37 | + * @property {Function} _flushCodePointsConsumedAsCharacterReference |
36 | 38 | * @property {string} lastStartTagName
|
37 | 39 | * @property {number} consumedAfterSnapshot
|
38 | 40 | * @property {boolean} active
|
39 | 41 | * @property {HiddenToken|undefined} currentCharacterToken
|
40 | 42 | * @property {HiddenToken|undefined} currentToken
|
41 | 43 | * @property {unknown} currentAttr
|
| 44 | + * @property {Function} NAMED_CHARACTER_REFERENCE_STATE |
| 45 | + * @property {Function} NUMERIC_CHARACTER_REFERENCE_END_STATE |
42 | 46 | *
|
43 | 47 | * @typedef {Object.<string, unknown> & {location: P5Location}} HiddenToken
|
44 | 48 | *
|
@@ -359,7 +363,20 @@ export const raw =
|
359 | 363 | // See the code for `parse` and `parseFragment`:
|
360 | 364 | // See: <https://github.com/inikulin/parse5/blob/9c683e1/packages/parse5/lib/parser/index.js#L371>.
|
361 | 365 | tokenizer.write(node.value)
|
362 |
| - parser._runParsingLoop(undefined) |
| 366 | + parser._runParsingLoop(null) |
| 367 | + |
| 368 | + // Character references hang, so if we ended there, we need to flush |
| 369 | + // those too. |
| 370 | + // We reset the preprocessor as if the document ends here. |
| 371 | + // Then one single call to the relevant state does the trick, parse5 |
| 372 | + // consumes the whole token. |
| 373 | + if ( |
| 374 | + tokenizer.state === 'NAMED_CHARACTER_REFERENCE_STATE' || |
| 375 | + tokenizer.state === 'NUMERIC_CHARACTER_REFERENCE_END_STATE' |
| 376 | + ) { |
| 377 | + preprocessor.lastChunkWritten = true |
| 378 | + tokenizer[tokenizer.state](tokenizer._consume()) |
| 379 | + } |
363 | 380 |
|
364 | 381 | // Process final characters if they’re still there after hibernating.
|
365 | 382 | // Similar to:
|
|
0 commit comments