Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
add text node
  • Loading branch information
wongchichong committed Mar 1, 2023
commit f4afdee4036d5335fd01f6b51c22e5488ccb331a
9 changes: 9 additions & 0 deletions src/vhtml.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,14 @@ export default function h(name: string | Function | null, attrs: any, ..._args:
}
}
}
else if (name === 'text') {
if (attrs) for (let i in attrs) {
if (attrs[i] !== false && attrs[i] != null && i !== setInnerHTMLAttr) {
//@ts-ignore
s += ` ${DOMAttributeNames[i] ? DOMAttributeNames[i] : esc(i)}="${esc(attrs[i])}"`
}
}
}
else {
s += '<' + name
if (attrs) for (let i in attrs) {
Expand Down Expand Up @@ -67,6 +75,7 @@ export default function h(name: string | Function | null, attrs: any, ..._args:

if (name === '!')
s += ' -->'
else if (name === 'text') { }
else
s += name ? `</${name}>` : ''
}
Expand Down
9 changes: 9 additions & 0 deletions test/vhtml.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,15 @@ describe('vhtml', () => {
`<svg viewBox="0 0 100 100"><g transform="translate(50, 50)"><circle class="clock-face" r="48"></circle><line class="millisecond" y2="-44"></line><line class="hour" y2="-22"></line><line class="minute" y2="-32"></line><line class="second" y2="-38"></line></g></svg>`
)
})

it('should support text', () => {
expect(
h('text', null, "hello world!")
).to.equal(
`hello world!`
)
})

it('should support empty comment', () => {
expect(
h('!', null)
Expand Down