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

dogma-html-parser

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

dogma-html-parser

HTML parser and compiler

  • 0.0.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
0
decreased by-100%
Maintainers
1
Weekly downloads
 
Created
Source

dogma-html-parser

HTML parser and compiler.

Parser

To parse an HTML string into an AST you can do the following:

import {parse} from 'dogma-html-parser'

const html = '<div class="test">Foo bar</div>'
const ast = parse(html)

The above example will set the constant ast to the following AST:

{
  "attributes": {
    "class": "test"
  },
  "children": [
    {
      "text": "Foo bar",
      "type": "text"
    }
  ],
  "name": "div",
  "type": "element"
}

It is worth noting the parser tries to be forgiving in terms of invalid whitespace, and by default will strip out unnecessary whitespace that doesn't actually get rendered by browsers. For example if you parse then compile the following:

< div > Test < /div >

You'll end up with:

<div>Test</div>

Compiler

The compiler simply takes an AST and converts it to an HTML string like so:

import {compile} from 'dogma-html-parser'

const ast = {
  attributes: {
    'class': 'test',
  },
  children: [
    {
      text: 'Foo bar',
      type: 'text',
    },
  ],
  name: 'div',
  type: 'element',
}

const html = compile(ast)

The above example will set the constant html to the following HTML string:

<div class="test">Foo bar</div>

Keywords

FAQs

Package last updated on 16 Sep 2017

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