Comparing version 0.2.1 to 0.2.2
@@ -26,8 +26,8 @@ var Stream = require('stream').Stream; | ||
else if (name === 'close') { | ||
var level = parser.tags.reduce(function (sum, t) { | ||
return sum + (opts.special.indexOf(t.name) < 0 ? 1 : 0); | ||
}, 0); | ||
selectors.forEach(function (sel) { | ||
var up = sel.updating; | ||
var level = parser.tags.reduce(function (sum, t) { | ||
return sum + (opts.special.indexOf(t.name) < 0 ? 1 : 0); | ||
}, 0); | ||
sel.pending = sel.pending.filter(function (p) { | ||
@@ -93,5 +93,8 @@ var done = level < p.level; | ||
function createSelector (selector, fn, special) { | ||
var saveSiblings = false; | ||
var parts = selector.split(/([\s>+]+)/).map(function (s) { | ||
if (s.match(/^\s+$/)) return; | ||
var op = s.trim(); | ||
if (op === '+') saveSiblings = true; | ||
if (op === '>' || op === '+') return { combinator : op }; | ||
@@ -120,2 +123,4 @@ | ||
var siblings = []; | ||
var sel = function (tag, parser) { | ||
@@ -125,2 +130,8 @@ var tags = parser.tags.filter(function (t) { | ||
}); | ||
if (special.indexOf(tag.name) < 0) { | ||
if (!siblings[tags.length]) siblings[tags.length] = []; | ||
siblings[tags.length].push(tag); | ||
} | ||
if (depth > tags.length) return; | ||
@@ -132,10 +143,31 @@ | ||
function check (t, p) { | ||
// try to falsify the hypothesis on each tag/part match: | ||
if (p.name !== '*' && p.name && p.name !== t.name) return false; | ||
if (p.class && p.class !== t.attributes.class) return false; | ||
if (p.id && p.id !== t.attributes.id) return false; | ||
return true; | ||
} | ||
for (; j >= 0; j--, i--) { | ||
var t = tags[i]; | ||
var p = parts[j]; | ||
// try to falsify the hypothesis on each tag/part match: | ||
if (p.name && p.name !== t.name) return; | ||
if (p.class && p.class !== t.attributes.class) return; | ||
if (p.id && p.id !== t.attributes.id) return; | ||
if (p.combinator === '>') { | ||
for (var ii = i; ii >= 0; ii--) { | ||
if (check(tags[ii], parts[j-1])) { | ||
break; | ||
} | ||
} | ||
if (ii < 0) return; | ||
j -= 2; | ||
} | ||
else if (p.combinator === '+') { | ||
var ts = siblings[i + 2]; | ||
t = ts[ts.length - 2]; | ||
if (!t) return; | ||
p = parts[j - 1]; | ||
if (!check(t, p)) return; | ||
j -= 2; | ||
} | ||
else if (!check(t, p)) return; | ||
} | ||
@@ -142,0 +174,0 @@ |
{ | ||
"name" : "trumpet", | ||
"version" : "0.2.1", | ||
"version" : "0.2.2", | ||
"description" : "parse and transform streaming html using css selectors", | ||
@@ -5,0 +5,0 @@ "main" : "index.js", |
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
22188
20
413
246
7