Skip to content

Commit cb42564

Browse files
committed
pr #16
1 parent 01b2510 commit cb42564

7 files changed

Lines changed: 16 additions & 9 deletions

File tree

src/serialize-markdown.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,11 @@ function serialize(node: VNode | VElement, context: SerializeContext = {
5353
count: 0,
5454
}): string {
5555
if (node.nodeType === VNode.DOCUMENT_FRAGMENT_NODE) {
56-
return (node.children || []).map(c => serialize(c, { ...context })).join('')
56+
return (node.childNodes || []).map(c => serialize(c, { ...context })).join('')
5757
}
5858
else if (isVElement(node)) {
5959
const tag: string = node.tagName.toLowerCase()
60-
const handleChildren = (ctx?: Partial<SerializeContext>): string => (node.children || []).map(c => serialize(c, { ...context, ...ctx })).join('')
60+
const handleChildren = (ctx?: Partial<SerializeContext>): string => (node.childNodes || []).map(c => serialize(c, { ...context, ...ctx })).join('')
6161
const fn = rules[tag]
6262
if (fn)
6363
return fn(node as VElement, handleChildren, context)

src/serialize-plaintext.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,13 @@ function serialize(node: VNode | VElement, context: SerializeContext = {
1313
count: 0,
1414
}): string {
1515
if (node.nodeType === VNode.DOCUMENT_FRAGMENT_NODE) {
16-
return node.children.map(c => serialize(c, { ...context })).join('')
16+
return node.childNodes.map(c => serialize(c, { ...context })).join('')
1717
}
1818

1919
else if (isVElement(node)) {
2020
const tag: string = node.tagName.toLowerCase()
2121

22-
const handleChildren = (ctx?: Partial<SerializeContext>): string => node.children.map(c => serialize(c, { ...context, ...ctx })).join('')
22+
const handleChildren = (ctx?: Partial<SerializeContext>): string => node.childNodes.map(c => serialize(c, { ...context, ...ctx })).join('')
2323

2424
const rules: Record<string, () => string> = {
2525
br: () => `${handleChildren()}\n`,

src/serialize-safehtml.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,11 @@ function serialize(node: VNode, context: SerializeContext = {
3131
count: 0,
3232
}): string {
3333
if (node.nodeType === VNode.DOCUMENT_FRAGMENT_NODE) {
34-
return (node.children || []).map(c => serialize(c, { ...context })).join('')
34+
return (node.childNodes || []).map(c => serialize(c, { ...context })).join('')
3535
}
3636
else if (isVElement(node)) {
3737
const tag: string = node.tagName?.toLowerCase()
38-
const handleChildren = (ctx?: Partial<SerializeContext>): string => (node.children || []).map(c => serialize(c, { ...context, ...ctx })).join('')
38+
const handleChildren = (ctx?: Partial<SerializeContext>): string => (node.childNodes || []).map(c => serialize(c, { ...context, ...ctx })).join('')
3939
const fn = baseRules[tag]
4040
if (fn)
4141
return fn(node, handleChildren)

src/utils.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ describe('utils', () => {
1212

1313
const body = removeBodyContainer(doc)
1414
expect(body.render()).toMatchInlineSnapshot(
15-
`"<title>Hello Title</title>Hello world"`,
15+
`"<title>Hello Title</title>"`,
1616
)
1717
})
1818
})

src/vcss.spec.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,7 @@ describe('css', () => {
357357
<iframe src="https://www.youtube.com/watch?v=cqHqLQgVCgY" />
358358
</div>
359359
)
360-
// Should not throw, should return true for iframe
360+
// Should not throw, should return true for Fiframe
361361
expect(matchSelector('div[data-youtube-video] iframe', element.querySelector('iframe'))).toBe(true)
362362
// Should return true for div
363363
expect(matchSelector('div[data-youtube-video]', element)).toBe(true)

src/vdom.spec.tsx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -724,4 +724,11 @@ describe('vdom', () => {
724724
// div.remove()
725725
// div.replaceWith('x')
726726
// })
727+
728+
729+
it('should include only elements in children', () => {
730+
const el: VElement = parseHTML('<div> <p>Hello</p> </div>').firstChild
731+
expect(el.childNodes).toHaveLength(3)
732+
expect(el.children).toHaveLength(1)
733+
})
727734
})

src/vdom.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ export class VNode {
187187
}
188188

189189
get children() {
190-
return this._childNodes || []
190+
return (this._childNodes || []).filter<any>(isVElement)
191191
}
192192

193193
get firstChild() {

0 commit comments

Comments
 (0)