Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@ayn/htmljs

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@ayn/htmljs

Generate HTML5 with javascript.

  • 1.0.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

HTMLjs

Build Status Build Status

A tiny beautiful HTML markup generator.

Core for PageJS. Need XML? Checkout XMLjs.

API

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

<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="utf-8">
        <title>Hello World!</title>
    </head>
    <body>
        <div><span>I am a span inside a div.</span>
            <h1 style="color: red;">Cool, uh?<br><span>I am inside h1, so I am red too!</span></h1>
        </div>
    </body>
</html>

Constructor

Constructor takes a single object used for configuration, here are the default values:

{
    doctype: '<!doctype html>',
    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,
    }
}

Methods

There is only one method.

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.

new htmljs().getMarkup({
    div: {
        attributes: { style: 'background: purple' },
        content: 'wowza',
        children: []
    }
})

License

MIT

Keywords

FAQs

Package last updated on 04 Sep 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc