File tree Expand file tree Collapse file tree 3 files changed +24
-5
lines changed
Expand file tree Collapse file tree 3 files changed +24
-5
lines changed Original file line number Diff line number Diff line change @@ -753,13 +753,15 @@ exports.html = function (str) {
753753 return html ( this [ 0 ] . children , this . options ) ;
754754 }
755755
756- var opts = this . options ;
756+ var opts = Object . apply ( { } , this . options ) ; // keep main options
757757
758758 return domEach ( this , function ( _ , el ) {
759759 el . children . forEach ( function ( child ) {
760760 child . next = child . prev = child . parent = null ;
761761 } ) ;
762762
763+ opts . context = el ;
764+
763765 var content = str . cheerio
764766 ? str . clone ( ) . get ( )
765767 : parse ( '' + str , opts , false ) . children ;
Original file line number Diff line number Diff line change @@ -2,12 +2,16 @@ var parse5 = require('parse5');
22var htmlparser2Adapter = require ( 'parse5-htmlparser2-tree-adapter' ) ;
33
44exports . parse = function ( content , options , isDocument ) {
5- var parse = isDocument ? parse5 . parse : parse5 . parseFragment ;
6-
7- return parse ( content , {
5+ var opts = {
86 treeAdapter : htmlparser2Adapter ,
97 sourceCodeLocationInfo : options . sourceCodeLocationInfo ,
10- } ) ;
8+ } ;
9+
10+ var context = options . context ;
11+
12+ return isDocument
13+ ? parse5 . parse ( content , opts )
14+ : parse5 . parseFragment ( context , content , opts ) ;
1115} ;
1216
1317exports . render = function ( dom ) {
Original file line number Diff line number Diff line change @@ -1611,6 +1611,19 @@ describe('$(...)', function () {
16111611 $remove . replaceWith ( $children ) ;
16121612 expect ( $fruits . children ( ) ) . toHaveLength ( 4 ) ;
16131613 } ) ;
1614+
1615+ it ( '(script value) : should add content as text' , function ( ) {
1616+ var $data = '<a><b>' ;
1617+ var $script = $ ( '<script>' ) . html ( $data ) ;
1618+
1619+ expect ( $script ) . toHaveLength ( 1 ) ;
1620+ expect ( $script [ 0 ] . type ) . toBe ( 'script' ) ;
1621+ expect ( $script [ 0 ] . name ) . toBe ( 'script' ) ;
1622+
1623+ expect ( $script [ 0 ] . children ) . toHaveLength ( 1 ) ;
1624+ expect ( $script [ 0 ] . children [ 0 ] . type ) . toBe ( 'text' ) ;
1625+ expect ( $script [ 0 ] . children [ 0 ] . data ) . toBe ( $data ) ;
1626+ } ) ;
16141627 } ) ;
16151628
16161629 describe ( '.toString' , function ( ) {
You can’t perform that action at this time.
0 commit comments