Skip to content

Commit a11409e

Browse files
committed
feat: 🎸 improve parseTemplate api
1 parent c5e4e32 commit a11409e

File tree

4 files changed

+9
-4
lines changed

4 files changed

+9
-4
lines changed

.changeset/fuzzy-areas-clap.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@hyperse/html-webpack-plugin-loader": patch
3+
---
4+
5+
improve parseTemplate api

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ A utility function that provides a convenient way to parse and modify HTML templ
166166
import { parseTemplate } from '@hyperse/html-webpack-plugin-loader';
167167

168168
// Parse and modify HTML template in one go
169-
const modifiedHtml = parseTemplate(htmlSource, templateOptions);
169+
const modifiedHtml = parseTemplate(htmlSource, templateOptions).serialize();
170170
```
171171

172172
The `parseTemplate` function is a shorthand for creating a `TemplateParser` instance and applying all template modifications at once. It accepts two parameters:

src/loader/htmlLoader.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ export default function htmlLoader(
4747
'const parseTemplate = ' + parseTemplate.toString() + ';',
4848
'const source = ' + JSON.stringify(source) + ';',
4949
'module.exports = (function(templateParams) { ',
50-
'return parseTemplate(source, templateParams || {});',
50+
'return parseTemplate(source, templateParams || {}).serialize();',
5151
'});',
5252
].join('');
5353
}

src/parser/parseTemplate.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { TemplateParser } from './TemplateParser.js';
1010
export const parseTemplate = (
1111
htmlSource: string,
1212
options: TemplateOptions = {}
13-
): string => {
13+
): TemplateParser => {
1414
const parser = new TemplateParser(htmlSource);
1515

1616
if (options.title) {
@@ -49,5 +49,5 @@ export const parseTemplate = (
4949
parser.upsertBodyScripts(options.bodyScripts);
5050
}
5151

52-
return parser.serialize();
52+
return parser;
5353
};

0 commit comments

Comments
 (0)