HTML Parser for NodeJS providing a lightweight object oriented interface
npm i node-html-light --save
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.
- 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
const Document = require('node-html-light').Document
const resolve = require('path').resolve
Document.fromPath(resolve('./index.html')).then((document) => {
// head is an instance of Node
const head = document.head()
// body is an instance of Node
const body = document.body()
// find child elements
// append child elements
// remove child elements
// replace child elements
return document.toHtml()
}).then((html) => {
// ..
})
const Node = require('node-html-light').Node
const resolve = require('path').resolve
Node.fromPath(resolve('partial.html')).then((node) => {})
const Node = require('node-html-light').Node
const node = Node.fromString('<div></div>')
const Node = require('node-html-light').Node
const Attributes = require('node-html-light').Attributes
const node = Node.of('meta', Attributes.of({
'name': 'viewport',
'theme-color': '#795548'
})
)
const Node = require('node-html-light').Node
const Attributes = require('node-html-light').Attributes
const resolve = require('path').resolve
Node.fromPath(resolve('partial.html')).then((node) => {
const content = node.find('div', Attributes.of({
'name': 'viewport',
'theme-color': '#795548'
}))
})
This project is distributed under the MIT license.