Skip to content

Commit

Permalink
Fixed Missing HTML Instructions #32
Browse files Browse the repository at this point in the history
  • Loading branch information
soranoo committed Mar 16, 2024
1 parent e456f02 commit c2e71a4
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "next-css-obfuscator",
"version": "2.2.14",
"version": "2.2.15",
"description": "A package deeply inspired by PostCSS-Obfuscator but for Next.js.",
"main": "dist/index.js",
"type": "commonjs",
Expand Down
13 changes: 13 additions & 0 deletions src/handlers/html.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -201,4 +201,17 @@ describe("obfuscateHtmlClassNames", () => {
expect(result.obfuscatedContent).toEqual(`<div class="key a b c"></div>`);
expect(result.usedKeys).to.deep.equal([".foo", ".bar", ".baz"]);
});

it("should handle HTML instruction", () => {
// Arrange
const html = `<!DOCTYPE html><div class="foo"></div>`;
const selectorConversion: SelectorConversion = { ".foo": ".a" };

// Act
const result = obfuscateHtmlClassNames({ html, selectorConversion });

// Assert
expect(result.obfuscatedContent).toEqual(`<!DOCTYPE html><div class="a"></div>`);
expect(result.usedKeys).to.deep.equal([".foo"]);
});
});
3 changes: 3 additions & 0 deletions src/handlers/html.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,9 @@ function obfuscateHtmlClassNames({
const usedKeys: string[] = [];

const parser = new htmlparser2.Parser({
onprocessinginstruction(name, data) {
modifiedHtml += `<${data}>`;
},
onopentag(tagName, attribs) {
if (tagName === "script") {
isScriptTag = true;
Expand Down

0 comments on commit c2e71a4

Please sign in to comment.