Skip to content

HTML-like string to DOM-like Javascript Object

License

Notifications You must be signed in to change notification settings

DenisPower1/hop

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Hop

Hop is a lightweight parser that converts an HTML-like string into a DOM-like JavaScript object. It was created to be used in Inter HTML intellisense, and it exposes the parseHTML function, which, as the name suggests, is used to parse the HTML-like string and returns an array of objects (HTML-like elements).

 import {  parseHTML  } from "./core/index"


  parseHTML(`
     <div id="app">
     <p _if="available" class="check"> This one is available </p>
     <p  _else> This one is not available </p>
     </div>
      
  `)

/**
 * Result:
 * [
  {
    type: 'Tag',
    tag: 'div',
    tagStart: 5,
    tagEnd: 18,
    attrs: [ [Object] ]
  },
  {
    type: 'Tag',
    tag: 'p',
    tagStart: 24,
    tagEnd: 56,
    attrs: [ [Object], [Object] ]
  },
  {
    type: 'Tag',
    tag: 'p',
    tagStart: 89,
    tagEnd: 98,
    attrs: [ [Object] ]
  }
]
 * 
 * 
 * 
 */

As stated earlier, it was created to enhance The inter's extension linting system, so it comes with some drawbacks, such as:

  • No nested elements.
  • It does not include Text Nodes.

About

HTML-like string to DOM-like Javascript Object

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published