Skip to content
This repository was archived by the owner on Jan 6, 2025. It is now read-only.

Repository files navigation

Node HTML Light

Build StatusDependency StatusDevDependency StatusNpm downloadsNpm VersionGit tagGithub issuesLicense

HTML Parser for NodeJS providing a lightweight object oriented interface

How can I install it?

npminode-html-light--save

Who is using it?

blauspecht.io uses node-html-light to render their whole page server-side. blauspecht.io enables you to provide rich content to your followers, schedule tweets and threads and will add AI-powered features soon.

How can I use it?

Document

Class methods

Instance methods

  • html() -> Node
  • head() -> Node
  • body() -> Node
  • toHtml() -> String

Node

Class methods

  • static fromPath(path) -> Node | Array<Node>
  • static fromString(string) -> Node | Array<Node>
  • static of(object | name, attrs) -> Node | Array<Node>

Instance properties

  • name
  • type
  • parent
  • children
  • root
  • nextSibling
  • previousSibling
  • attributes

Instance methods

  • appendChild(newChild) -> void
  • appendChildBefore(newChild, oldChild) -> void
  • appendChildAfter(newChild, oldChild) -> void
  • find(element, attrs, limit) -> Array<Node>
  • filter(callback, limit) -> Array<Node>
  • removeChild(child) -> void
  • replaceChild(newChild, oldChild) -> void
  • toHtml() -> String

Attributes

Class methods

  • static of(object) -> Array

Text

Class methods

  • static of(string) -> Text

Examples

Create a document using a file

constDocument=require('node-html-light').Documentconstresolve=require('path').resolveDocument.fromPath(resolve('./index.html')).then((document)=>{// head is an instance of Nodeconsthead=document.head()// body is an instance of Nodeconstbody=document.body()// find child elements// append child elements// remove child elements// replace child elementsreturndocument.toHtml()}).then((html)=>{// ..})

Create a Node using a File

constNode=require('node-html-light').Nodeconstresolve=require('path').resolveNode.fromPath(resolve('partial.html')).then((node)=>{})

Create a Node using a String

constNode=require('node-html-light').Nodeconstnode=Node.fromString('<div></div>')

Create a Node with raw data

constNode=require('node-html-light').NodeconstAttributes=require('node-html-light').Attributesconstnode=Node.of('meta',Attributes.of({'name': 'viewport','theme-color': '#795548'}))

Find a child Node of an existing Element

constNode=require('node-html-light').NodeconstAttributes=require('node-html-light').Attributesconstresolve=require('path').resolveNode.fromPath(resolve('partial.html')).then((node)=>{constcontent=node.find('div',Attributes.of({'name': 'viewport','theme-color': '#795548'}))})

License

This project is distributed under the MIT license.

About

HTML Parser for NodeJS providing a lightweight object oriented interface

Topics

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages