File tree 2 files changed +42
-0
lines changed
2 files changed +42
-0
lines changed Original file line number Diff line number Diff line change @@ -197,6 +197,15 @@ function element(node, state) {
197
197
* Nothing.
198
198
*/
199
199
function text ( node , state ) {
200
+ // Allow `DATA` through `PLAINTEXT`,
201
+ // but when hanging in a tag for example,
202
+ // switch back to `DATA`.
203
+ // Note: `State` is not exposed by `parse5`, so these numbers are fragile.
204
+ // See: <https://github.com/inikulin/parse5/blob/46cba43/packages/parse5/lib/tokenizer/index.ts#L58>
205
+ if ( state . parser . tokenizer . state > 4 ) {
206
+ state . parser . tokenizer . state = 0
207
+ }
208
+
200
209
/** @type {CharacterToken } */
201
210
const token = {
202
211
type : Token . TokenType . CHARACTER ,
Original file line number Diff line number Diff line change @@ -409,6 +409,39 @@ test('raw', async function (t) {
409
409
}
410
410
)
411
411
412
+ await t . test ( 'should switch to data state at a text node' , async function ( ) {
413
+ assert . deepEqual (
414
+ raw ( {
415
+ type : 'root' ,
416
+ children : [
417
+ { type : 'raw' , value : '<details>\n<summary>Complete logs</summary' } ,
418
+ { type : 'text' , value : '\n' } ,
419
+ { type : 'raw' , value : '</details>' }
420
+ ]
421
+ } ) ,
422
+ {
423
+ type : 'root' ,
424
+ data : { quirksMode : false } ,
425
+ children : [
426
+ {
427
+ type : 'element' ,
428
+ tagName : 'details' ,
429
+ properties : { } ,
430
+ children : [
431
+ { type : 'text' , value : '\n' } ,
432
+ {
433
+ type : 'element' ,
434
+ tagName : 'summary' ,
435
+ properties : { } ,
436
+ children : [ { type : 'text' , value : 'Complete logs\n' } ]
437
+ }
438
+ ]
439
+ }
440
+ ]
441
+ }
442
+ )
443
+ } )
444
+
412
445
await t . test (
413
446
'should support raw nodes (security, unsafe)' ,
414
447
async function ( ) {
You can’t perform that action at this time.
0 commit comments