himalaya
Advanced tools
Comparing version 0.2.10 to 0.2.11
@@ -210,3 +210,6 @@ (function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.himalaya = f()}})(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){ | ||
dt: ['dl'], | ||
dd: ['dl'] | ||
dd: ['dl'], | ||
tbody: ['table'], | ||
thead: ['table'], | ||
tfoot: ['table'] | ||
}; | ||
@@ -213,0 +216,0 @@ |
@@ -45,3 +45,6 @@ 'use strict'; | ||
dt: ['dl'], | ||
dd: ['dl'] | ||
dd: ['dl'], | ||
tbody: ['table'], | ||
thead: ['table'], | ||
tfoot: ['table'] | ||
}; | ||
@@ -48,0 +51,0 @@ |
{ | ||
"name": "himalaya", | ||
"description": "HTML to JSON parser", | ||
"version": "0.2.10", | ||
"version": "0.2.11", | ||
"author": "Chris Andrejewski <christopher.andrejewski@gmail.com>", | ||
@@ -35,3 +35,3 @@ "ava": { | ||
"devDependencies": { | ||
"ava": "^0.19.1", | ||
"ava": "^0.22.0", | ||
"babel-core": "^6.24.0", | ||
@@ -48,3 +48,3 @@ "babel-plugin-istanbul": "^4.0.0", | ||
"gulp": "^3.9.1", | ||
"gulp-babel": "^6.1.2", | ||
"gulp-babel": "^7.0.0", | ||
"gulp-sourcemaps": "^2.1.1", | ||
@@ -51,0 +51,0 @@ "nyc": "^11.0.2", |
# Himalaya | ||
A pure JavaScript HTML parser that converts HTML into JSON, which can then be further manipulated by other modules. | ||
> Parse HTML into JSON | ||
```bash | ||
npm install himalaya | ||
``` | ||
[![npm](https://img.shields.io/npm/v/himalaya.svg)](https://www.npmjs.com/package/himalaya) | ||
@@ -14,4 +10,11 @@ [![Build Status](https://travis-ci.org/andrejewski/himalaya.svg?branch=master)](https://travis-ci.org/andrejewski/himalaya) | ||
[Try online 🚀](http://andrejewski.github.io/himalaya) | ||
## Usage | ||
### Node | ||
```bash | ||
npm install himalaya | ||
``` | ||
```js | ||
@@ -24,5 +27,21 @@ var himalaya = require('himalaya') | ||
Installed globally, Himalaya includes a command-line tool to convert HTML files to JSON files, or as a pipe transform. | ||
### Browser | ||
Download [himalaya.js](https://github.com/andrejewski/himalaya/blob/master/docs/dist/himalaya.js) and put it in a `<script>` tag. Himalaya will be accessible from `window.himalaya`. | ||
```js | ||
var html = "<div>Hello world</div>" | ||
var json = himalaya.parse(html) | ||
console.log('👉', json) | ||
``` | ||
Himalaya can be bundled with your code using tools like Browersify and Webpack. | ||
### Command-line | ||
Himalaya includes a command-line tool. | ||
```bash | ||
npm install --global himalaya | ||
``` | ||
```bash | ||
himalaya webpage.html webpage.json | ||
@@ -48,3 +67,3 @@ # or as a pipe | ||
```json | ||
```js | ||
[ | ||
@@ -106,3 +125,3 @@ { | ||
### Preserves Whitespace | ||
Himalaya does not cut corners and returns an accurate representation of the HTML supplied. | ||
Himalaya does not cut corners and returns an accurate representation of the HTML supplied. To remove whitespace, post-process the JSON; check out [an example script](https://gist.github.com/andrejewski/773487d4f4a46b16865405d7b74eabf9). | ||
@@ -109,0 +128,0 @@ ## Going back to HTML |
@@ -30,3 +30,6 @@ import lexer from './lexer' | ||
dt: ['dl'], | ||
dd: ['dl'] | ||
dd: ['dl'], | ||
tbody: ['table'], | ||
thead: ['table'], | ||
tfoot: ['table'] | ||
} | ||
@@ -33,0 +36,0 @@ |
@@ -327,1 +327,45 @@ import test from 'ava' | ||
}) | ||
test('parser() should handle nested tables', t => { | ||
const str = '<table><tbody><tr><td><table><tbody></tbody></table></td></tr></tbody></table>' | ||
const tokens = lexer(str, lexerOptions) | ||
const nodes = parser(tokens, { | ||
voidTags: [], | ||
closingTags: ['tbody'], | ||
closingTagAncestorBreakers: { | ||
tbody: ['table'] | ||
} | ||
}) | ||
t.deepEqual(nodes, [{ | ||
type: 'element', | ||
tagName: 'table', | ||
attributes: [], | ||
children: [{ | ||
type: 'element', | ||
tagName: 'tbody', | ||
attributes: [], | ||
children: [{ | ||
type: 'element', | ||
tagName: 'tr', | ||
attributes: [], | ||
children: [{ | ||
type: 'element', | ||
tagName: 'td', | ||
attributes: [], | ||
children: [{ | ||
type: 'element', | ||
tagName: 'table', | ||
attributes: [], | ||
children: [{ | ||
type: 'element', | ||
tagName: 'tbody', | ||
attributes: [], | ||
children: [] | ||
}] | ||
}] | ||
}] | ||
}] | ||
}] | ||
}]) | ||
}) |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
386576
3099
160