0.1.1 • Published 6 years ago

hast-to-snabbdom v0.1.1

Weekly downloads
1
License
ISC
Repository
github
Last release
6 years ago

hast-to-snabbdom

Transform a HAST into a Snabbdom tree.

npm version build status ISC-licensed chat on gitter

Installing

npm install hast-to-snabbdom

Usage

This is our input HTML Abstract Syntax Tree (HAST):

const u = require('unist-builder')

const uTree = u('element', {
	tagName: 'form',
	properties: {
		id: 'a',
		className: ['b', 'c']
	}
}, [
	u('text', 'hey there!'),
	u('comment', 'i am a comment'),
	u('element', {
		tagName: 'input',
		properties: {type: 'file'}
	}, [])
])

Let's convert it into a Snabbdom tree and print the result:

const toSnabbdom = require('hast-to-snabbdom')
const util = require('util')

const sTree = toSnabbdom(uTree)
console.log(util.inspect(sTree, {depth: Infinity}))
{
	sel: 'form#a.b.c',
	data: {},
	children: [ {
		sel: undefined,
		data: undefined,
		children: undefined,
		text: 'hey there!',
		elm: undefined,
		key: undefined
	}, {
		sel: 'input',
		data: {type: 'file'},
		children: [],
		text: undefined,
		elm: undefined,
		key: undefined
	} ],
	text: undefined,
	elm: undefined,
	key: undefined
}

Contributing

If you have a question or have difficulties using hast-to-snabbdom, please double-check your code and setup first. If you think you have found a bug or want to propose a feature, refer to the issues page.