1- import type { DefaultTreeAdapterTypes } from 'parse5' ;
2- import { serialize } from 'parse5' ;
1+ import { type DefaultTreeAdapterTypes , parseFragment , serialize } from 'parse5' ;
32import type {
43 ScriptInlineItem ,
54 ScriptItem ,
@@ -16,9 +15,9 @@ import { upsertScripts } from './upsertScripts.js';
1615import { upsertTitle } from './upsertTitle.js' ;
1716
1817export class TemplateParser {
19- private document : DefaultTreeAdapterTypes . Document ;
20- private head : DefaultTreeAdapterTypes . Element ;
21- private body : DefaultTreeAdapterTypes . Element ;
18+ protected readonly document : DefaultTreeAdapterTypes . Document ;
19+ protected readonly head : DefaultTreeAdapterTypes . Element ;
20+ protected readonly body : DefaultTreeAdapterTypes . Element ;
2221
2322 constructor ( htmlSource : string ) {
2423 const { document, head, body } = parseDocument ( htmlSource ) ;
@@ -120,4 +119,13 @@ export class TemplateParser {
120119 public serialize ( ) : string {
121120 return serialize ( this . document ) ;
122121 }
122+
123+ /**
124+ * Parse a fragment of html
125+ * @param html - The html fragment to parse
126+ * @returns The parsed document fragment
127+ */
128+ public parseFragment ( html : string ) : DefaultTreeAdapterTypes . DocumentFragment {
129+ return parseFragment ( html ) ;
130+ }
123131}
0 commit comments