Generate HTML5 with javascript.
js
const htmljs = require('@ayn/htmljs')
let page = new htmljs({ title: 'Hello World!' })
.div(el=>{
el.span('I am a span inside a div.')
el.h1({ style: 'color: red;' },'Cool, uh?', el=>{
el.br()
el.span('I am inside h1, so I am red too!')
})
})
let markup = page.getMarkup()
`
Output
`html
Hello World!
I am a span inside a div.
Cool, uh?
I am inside h1, so I am red too!
`
$3
Constructor takes a single object used for configuration, here are the default values:
`js
{
doctype: '',
lang: 'en',
charset: 'utf-8',
title: 'Untitled paged',
body: 'No content.',
theme: null,
tags: {
self_closing: [
'area', 'base', 'br', 'col', 'embed', 'wbr', 'input',
'img', 'source', 'link', 'meta', 'param', 'hr', 'track'
],
autoclose: false,
}
}
`
$3
There is only one method.
`js
page.getMarkup()
`
Returns the markup code of the page or in the case of a child element (obtained through a tag callback) a subset of it.
Child elements also contain two properties el.parent and el.siblings.
You can also process objects directly.
`js
new htmljs().getMarkup({
div: {
attributes: { style: 'background: purple' },
content: 'wowza',
children: []
}
})
``