Parse HTML into JSON
Try online 🚀 | Read the specification 📖
npm install himalaya
import fs from 'fs'
import { parse } from 'himalaya'
const html = fs.readFileSync('/webpage.html', { encoding: 'utf8' })
const json = parse(html)
console.log('👉', json)
Download himalaya.js and put it in a <script> tag. Himalaya will be accessible from window.himalaya.
const html = '
Hello world
'
const json = window.himalaya.parse(html)
console.log('👉', json)
Himalaya bundles well with Browersify and Webpack.
Himalaya parsed me...
;[
{
type: 'element',
tagName: 'div',
attributes: [
{
key: 'class',
value: 'post post-featured',
},
],
children: [
{
type: 'element',
tagName: 'p',
attributes: [],
children: [
{
type: 'text',
content: 'Himalaya parsed me...',
},
],
},
{
type: 'comment',
content: ' ...and I liked it. ',
},
],
},
]
Note: In this example, text nodes consisting of whitespace are not shown for readability.
Himalaya transforms HTML into JSON, that's it. Himalaya is synchronous and does not require any complicated callbacks.
Himalaya handles a lot of HTML's fringe cases, like:
...
- Ignores extra closing tags...- Properly handles void tags likeand- Properly handles self-closing tags like- Handles<!doctype>and<-- comments -->- Does not parse the contents of
$ claude mcp add himalaya \
-- python -m otcore.mcp_server <graph>