Skip to content

Commit

Permalink
fix: html normalization
Browse files Browse the repository at this point in the history
  • Loading branch information
mlrawlings committed Nov 26, 2019
1 parent 728f73f commit 8bf3669
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,17 +103,19 @@ export function defaultNormalizer(container: ContainerNode) {
const document = container.ownerDocument!;
const treeWalker = document.createTreeWalker(
clone,
SHOW_ELEMENT & SHOW_COMMENT
SHOW_ELEMENT | SHOW_COMMENT
);

let node: Comment | Element;
while ((node = treeWalker.nextNode() as Comment | Element)) {
let nextNode = treeWalker.nextNode();
while ((node = nextNode as Comment | Element)) {
nextNode = treeWalker.nextNode();
if (node.nodeType === COMMENT_NODE) {
(node as Comment).remove();
} else {
Array.from((node as Element).attributes)
.map(attr => attr.name)
.filter(attrName => /^data-(w-|widget$|marko$)/.test(attrName))
.filter(attrName => /^data-(w-|widget$|marko(-|$))/.test(attrName))
.forEach(attrName => (node as Element).removeAttribute(attrName));
}
}
Expand Down
5 changes: 5 additions & 0 deletions test/components/container/fixtures/template.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<div
class="container"
>
Hello worldfoo
</div>
5 changes: 5 additions & 0 deletions test/components/container/fixtures/template.marko
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class {}

<container model="foo">
Hello world
</container>
1 change: 1 addition & 0 deletions test/components/hello/index.marko
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
class {}
<div>Hello ${input.name}!</div>
8 changes: 8 additions & 0 deletions test/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,14 @@ describe("findProjectFixtures", () => {
"render": [Function],
"toString": [Function],
},
"template": Object {
"ext": ".marko",
"fixture": [Component "(cwd)/test/components/container/fixtures/template.marko"],
"name": "template",
"path": "(cwd)/test/components/container/fixtures/template.marko",
"render": [Function],
"toString": [Function],
},
},
"fixturesPath": "(cwd)/test/components/container/fixtures",
"name": "container",
Expand Down

0 comments on commit 8bf3669

Please sign in to comment.