Comparing version 0.2.4 to 0.2.5
@@ -56,9 +56,11 @@ 'use strict'; | ||
// closing tag of the same name | ||
var _len = stack.length; | ||
while (--_len > -1) { | ||
if (tagName === stack[_len].tagName) { | ||
stack = stack.slice(0, _len); | ||
nodes = stack[_len - 1].children; | ||
var currentIndex = stack.length - 1; | ||
while (currentIndex > 0) { | ||
if (tagName === stack[currentIndex].tagName) { | ||
stack = stack.slice(0, currentIndex); | ||
var previousIndex = currentIndex - 1; | ||
nodes = stack[previousIndex].children; | ||
break; | ||
} | ||
currentIndex = currentIndex - 1; | ||
} | ||
@@ -65,0 +67,0 @@ } |
{ | ||
"name": "himalaya", | ||
"description": "HTML to JSON parser", | ||
"version": "0.2.4", | ||
"version": "0.2.5", | ||
"author": "Chris Andrejewski <christopher.andrejewski@gmail.com>", | ||
@@ -6,0 +6,0 @@ "ava": { |
@@ -9,2 +9,4 @@ # Himalaya | ||
[![Build Status](https://travis-ci.org/andrejewski/himalaya.svg?branch=master)](https://travis-ci.org/andrejewski/himalaya) | ||
## Usage | ||
@@ -11,0 +13,0 @@ |
@@ -46,9 +46,11 @@ export default function parser (tokens, options) { | ||
// closing tag of the same name | ||
let len = stack.length | ||
while (--len > -1) { | ||
if (tagName === stack[len].tagName) { | ||
stack = stack.slice(0, len) | ||
nodes = stack[len - 1].children | ||
let currentIndex = stack.length - 1 | ||
while (currentIndex > 0) { | ||
if (tagName === stack[currentIndex].tagName) { | ||
stack = stack.slice(0, currentIndex) | ||
const previousIndex = currentIndex - 1 | ||
nodes = stack[previousIndex].children | ||
break | ||
} | ||
currentIndex = currentIndex - 1 | ||
} | ||
@@ -55,0 +57,0 @@ } |
@@ -50,26 +50,63 @@ import test from 'ava' | ||
test('parser() should handle optional-close tags', t => { | ||
const parserOptions = { | ||
voidTags: [], | ||
closingTags: ['p'] | ||
{ | ||
const parserOptions = { | ||
voidTags: [], | ||
closingTags: ['p'] | ||
} | ||
const str = '<p>This is one<p>This is two</p>' | ||
const tokens = lexer(str, lexerOptions) | ||
const nodes = parser(tokens, parserOptions) | ||
t.deepEqual(nodes, [{ | ||
type: 'element', | ||
tagName: 'p', | ||
attributes: [], | ||
children: [{ | ||
type: 'text', | ||
content: 'This is one' | ||
}] | ||
}, { | ||
type: 'element', | ||
tagName: 'p', | ||
attributes: [], | ||
children: [{ | ||
type: 'text', | ||
content: 'This is two' | ||
}] | ||
}]) | ||
} | ||
const str = '<p>This is one<p>This is two</p>' | ||
const tokens = lexer(str, lexerOptions) | ||
const nodes = parser(tokens, parserOptions) | ||
t.deepEqual(nodes, [{ | ||
type: 'element', | ||
tagName: 'p', | ||
attributes: [], | ||
children: [{ | ||
type: 'text', | ||
content: 'This is one' | ||
}] | ||
}, { | ||
type: 'element', | ||
tagName: 'p', | ||
attributes: [], | ||
children: [{ | ||
type: 'text', | ||
content: 'This is two' | ||
}] | ||
}]) | ||
{ | ||
const parserOptions = { | ||
voidTags: [], | ||
closingTags: ['p', 'span'] | ||
} | ||
const str = '<p>This is one <span>okay<p>This is two</p>' | ||
const tokens = lexer(str, lexerOptions) | ||
const nodes = parser(tokens, parserOptions) | ||
t.deepEqual(nodes, [{ | ||
type: 'element', | ||
tagName: 'p', | ||
attributes: [], | ||
children: [{ | ||
type: 'text', | ||
content: 'This is one ' | ||
}, { | ||
type: 'element', | ||
tagName: 'span', | ||
attributes: [], | ||
children: [{ | ||
type: 'text', | ||
content: 'okay' | ||
}] | ||
}] | ||
}, { | ||
type: 'element', | ||
tagName: 'p', | ||
attributes: [], | ||
children: [{ | ||
type: 'text', | ||
content: 'This is two' | ||
}] | ||
}]) | ||
} | ||
}) | ||
@@ -76,0 +113,0 @@ |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
865123
9104
137
4