HTML Parser for NodeJS providing a lightweight object oriented interface
npminode-html-light--saveblauspecht.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.
- static fromPath(path) -> Node | Array<Node>
- static fromString(string) -> Node | Array<Node>
- static of(object | name, attrs) -> Node | Array<Node>
- name
- type
- parent
- children
- root
- nextSibling
- previousSibling
- attributes
- 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
- static of(object) -> Array
- static of(string) -> Text
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)=>{// ..})constNode=require('node-html-light').Nodeconstresolve=require('path').resolveNode.fromPath(resolve('partial.html')).then((node)=>{})constNode=require('node-html-light').Nodeconstnode=Node.fromString('<div></div>')constNode=require('node-html-light').NodeconstAttributes=require('node-html-light').Attributesconstnode=Node.of('meta',Attributes.of({'name': 'viewport','theme-color': '#795548'}))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'}))})This project is distributed under the MIT license.