@@ -117,6 +117,7 @@ interface IHTMLDocumentStructure {
117117export default class HTMLParser {
118118 private window : BrowserWindow ;
119119 private evaluateScripts : boolean = false ;
120+ private isTemplateDocumentFragment : boolean = false ;
120121 private rootNode : Element | DocumentFragment | Document | null = null ;
121122 private rootDocument : Document | null = null ;
122123 private nodeStack : Node [ ] = [ ] ;
@@ -134,18 +135,24 @@ export default class HTMLParser {
134135 * @param window Window.
135136 * @param [options] Options.
136137 * @param [options.evaluateScripts] Set to "true" to enable script execution
138+ * @param [options.isTemplateDocumentFragment] Set to "true" if parsing a template content fragment.
137139 */
138140 constructor (
139141 window : BrowserWindow ,
140142 options ?: {
141143 evaluateScripts ?: boolean ;
144+ isTemplateDocumentFragment ?: boolean ;
142145 }
143146 ) {
144147 this . window = window ;
145148
146149 if ( options ?. evaluateScripts ) {
147150 this . evaluateScripts = true ;
148151 }
152+
153+ if ( options ?. isTemplateDocumentFragment ) {
154+ this . isTemplateDocumentFragment = true ;
155+ }
149156 }
150157 /**
151158 * Parses HTML a root element containing nodes found.
@@ -545,6 +552,7 @@ export default class HTMLParser {
545552 this . currentNode = this . nodeStack [ this . nodeStack . length - 1 ] || this . rootNode ;
546553 }
547554 } else if (
555+ ! this . isTemplateDocumentFragment &&
548556 config ?. permittedParents &&
549557 ! config . permittedParents . includes ( parentLowerTagName ! )
550558 ) {
0 commit comments