1.1.0 • Published 6 years ago

h2ml v1.1.0

Weekly downloads
7
License
MIT
Repository
github
Last release
6 years ago

h2ml

h() that returns an HTML string.

import h from 'h2ml'

h('div', null, [
  h('span', { class: 'title' }, 'Hello world'),
  h('p', { class: 'body' },
    'Autem placeat illo libero voluptatem dolorem. ' +
    'Ut ' + h('b', null, 'consequatur neque harum') + ' sed molestias.'
  )
])

Embeds are not XSS secured. Combine it with a library like xss:

import h from 'h2ml'
import secure from 'xss'

var req = h('script', null, 'alert("hacked")')

h('span', null, secure(req))
// => '<span>&lt;script&gt;alert("hacked")&lt;/script&gt;</span>'

Usage

h(tag)

h(tag, data)

h(tag, data, children)

  • tag specifies the type of element.
  • data is the attributes.
  • children is an optional string or array of strings.
h('div', { class: 'foo' }, 'hello world')
// '<div class="foo">hello world</div>'

h('div', null, [
  h('span', 'foo'),
  h('span', 'bar')
])
// '<div><span>foo</span><span>bar</span></div>'
1.1.0

6 years ago

1.0.0

6 years ago

0.3.0

7 years ago

0.2.0

7 years ago

0.1.0

7 years ago