🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
Book a DemoInstallSign in
Socket

h5o

Package Overview
Dependencies
Maintainers
1
Versions
23
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

h5o - npm Package Compare versions

Comparing version

to
0.9.3

src/asHTML.js

132

dist/debug/bookmarklet.debug.js

@@ -51,3 +51,21 @@ /**

},{"./src/createOutline":6}],3:[function(require,module,exports){
},{"./src/createOutline":7}],3:[function(require,module,exports){
var asHTML = require("./asHTML");
function Outline(outlineTarget, onlySection) {
this.startingNode = outlineTarget.node;
this.sections = [onlySection];
}
Outline.prototype.getLastSection = function () {
return this.sections[this.sections.length - 1];
};
Outline.prototype.asHTML = function (createLinks) {
return asHTML(this.sections, createLinks);
};
module.exports = Outline;
},{"./asHTML":6}],4:[function(require,module,exports){
/**

@@ -66,4 +84,4 @@ * Internal data structure to avoid adding properties onto native objects

},{}],4:[function(require,module,exports){
var asHtml = require("./asHtml"),
},{}],5:[function(require,module,exports){
var asHTML = require("./asHTML"),
utils = require("./utils");

@@ -101,28 +119,26 @@

Section.prototype = {
Section.prototype.append = function (what) {
what.container = this;
this.sections.push(what);
};
append: function (what) {
what.container = this;
this.sections.push(what);
},
asHTML: function (createLinks) {
// @todo: this really belongs in a separate formatter type thing
Section.prototype.asHTML = function (createLinks) {
// @todo: this really belongs in a separate formatter type thing
if (!this.heading) {
// @todo: find formal proof if this is possible/not-possible
throw new Error("An implied heading should have been created at some point, but wasn't.");
}
if (!this.heading) {
// @todo: find formal proof if this is possible/not-possible
throw new Error("An implied heading should have been created at some point, but wasn't.");
}
var headingText = this.heading.implied
? "<i>Untitled " + utils.getTagName(this.startingNode) + "</i>"
: sectionHeadingText(this.heading);
var headingText = this.heading.implied
? "<i>Untitled " + utils.getTagName(this.startingNode) + "</i>"
: sectionHeadingText(this.heading);
if (createLinks) {
headingText = '<a href="#' + generateId(this.startingNode) + '">'
+ headingText
+ '</a>';
}
return headingText + asHtml(this.sections, createLinks);
if (createLinks) {
headingText = '<a href="#' + generateId(this.startingNode) + '">'
+ headingText
+ '</a>';
}
return headingText + asHTML(this.sections, createLinks);
};

@@ -132,4 +148,4 @@

},{"./asHtml":5,"./utils":7}],5:[function(require,module,exports){
module.exports = function (sections, createLinks) {
},{"./asHTML":6,"./utils":8}],6:[function(require,module,exports){
function asHTML(sections, createLinks) {
var retval = '';

@@ -142,28 +158,18 @@

return (retval == '' ? retval : '<ol>' + retval + '</ol>');
};
}
},{}],6:[function(require,module,exports){
module.exports = asHTML;
},{}],7:[function(require,module,exports){
var Section = require("./Section"),
Outline = require("./Outline"),
OutlineTarget = require("./OutlineTarget"),
asHtml = require("./asHtml"),
walk = require("./walk"),
utils = require("./utils");
function arrayLast(arr) {
return arr[arr.length - 1];
}
function getSectionHeadingRank(section) {
if (!utils.isHeading(section.heading)) {
// @todo: find formal proof if this is possible/not-possible
throw new Exception("What is the heading rank of an implied heading? Is this code even reachable?")
}
return utils.getHeadingElementRank(section.heading);
}
var currentOutlineTarget, currentSection, stack;
function stackTopNode() {
var top = arrayLast(stack);
return top ? top.node : undefined;
if (!stack.length) return;
return stack[stack.length - 1].node;
}

@@ -213,10 +219,3 @@

// as the only section in the outline.
// @todo: extract this into a new Outline()?
currentOutlineTarget.outline = {
sections: [currentSection],
startingNode: node,
asHTML: function (createLinks) {
return asHtml(this.sections, createLinks);
}
};
currentOutlineTarget.outline = new Outline(currentOutlineTarget.node, currentSection);
return;

@@ -245,10 +244,3 @@ }

// as the only section in the outline.
// @todo: extract this into a new Outline()?
currentOutlineTarget.outline = {
sections: [currentSection],
startingNode: node,
asHTML: function (createLinks) {
return asHtml(this.sections, createLinks);
}
};
currentOutlineTarget.outline = new Outline(currentOutlineTarget.node, currentSection);
return;

@@ -267,3 +259,3 @@ }

// outline target is an implied heading, then
} else if (arrayLast(currentOutlineTarget.outline.sections).heading.implied || utils.getHeadingElementRank(node) >= getSectionHeadingRank(arrayLast(currentOutlineTarget.outline.sections))) {
} else if (currentOutlineTarget.outline.getLastSection().heading.implied || utils.getHeadingElementRank(node) >= utils.getHeadingElementRank(currentOutlineTarget.outline.getLastSection().heading)) {

@@ -293,4 +285,18 @@ // create a new section and

do {
// note:
// if candidateSection is still currentSection - it definitely has a heading, because otherwise
// `node`, which is a heading, would be a heading for that section
// if the heading for currentSection is higher (or same), e.g. `node` is H2 and currentSection.heading is H1
// then our `node` creates a subsection and we don't need to care about anything else
// if our `node` is actually higher, e.g. `node` is H3, and currentSection.heading is H4
// H4 is not the last child of the outline target [and therefore not the only child]
// therefore there must exist an element of at least H3 or higher rank
// that is the outline parent of the H4 and that element of H3 or higher
// would then be hit by going upwards
// therefore getSectionHeadingRank is sure that candidateSection.heading is not implied
// If the element being entered has a rank lower than the rank of the heading of the candidate section, then
if (utils.getHeadingElementRank(node) < getSectionHeadingRank(candidateSection)) {
if (utils.getHeadingElementRank(node) < utils.getHeadingElementRank(candidateSection.heading)) {

@@ -363,3 +369,3 @@ // create a new section,

// Let current section be the last section in the outline of the current outline target element.
currentSection = arrayLast(currentOutlineTarget.outline.sections);
currentSection = currentOutlineTarget.outline.getLastSection();

@@ -443,3 +449,3 @@ // Append the outline of the sectioning content element being exited to the current section.

},{"./OutlineTarget":3,"./Section":4,"./asHtml":5,"./utils":7,"./walk":8}],7:[function(require,module,exports){
},{"./Outline":3,"./OutlineTarget":4,"./Section":5,"./utils":8,"./walk":9}],8:[function(require,module,exports){
function getTagName(el) {

@@ -492,3 +498,3 @@ return el.tagName.toUpperCase(); // upper casing due to http://ejohn.org/blog/nodename-case-sensitivity/

},{}],8:[function(require,module,exports){
},{}],9:[function(require,module,exports){
module.exports = function (root, enter, exit) {

@@ -495,0 +501,0 @@ var node = root;

@@ -11,2 +11,2 @@ /**

*/
!function a(b,c,d){function e(g,h){if(!c[g]){if(!b[g]){var i="function"==typeof require&&require;if(!h&&i)return i(g,!0);if(f)return f(g,!0);var j=new Error("Cannot find module '"+g+"'");throw j.code="MODULE_NOT_FOUND",j}var k=c[g]={exports:{}};b[g][0].call(k.exports,function(a){var c=b[g][1][a];return e(c?c:a)},k,k.exports,a,b,c,d)}return c[g].exports}for(var f="function"==typeof require&&require,g=0;g<d.length;g++)e(d[g]);return e}({1:[function(a){var b=a("./index"),c=function(a,b){for(var c=0;c<a.length;c++)a[c].setAttribute("style",b)},d="font-size:11px;font-family:Verdana, sans-serif;",e="position:fixed;top:10px;right:10px;border:2px solid #000;background:rgba(255,255,255,.9);padding:15px;z-index:999;max-height:400px;overflow:auto;",f="list-style:decimal outside;margin-left:20px;",g="margin: 0;padding:0;",h="color:#008;text-decoration:underline;",i="float: right; margin: 0 0 5px 5px; padding: 5px; border: 1px #008 solid;color:#00f;background-color:#ccf;",j=b(document.body).asHTML(!0),k=document.createElement("div");c([k],e+d),k.innerHTML=j,c(k.getElementsByTagName("li"),f+d),c(k.getElementsByTagName("ol"),g+d),c(k.getElementsByTagName("a"),h+d);var l=k.insertBefore(document.createElement("a"),k.firstChild);c([l],i),l.innerHTML="Close",l.href="#",l.onclick=function(a){document.body.removeChild(k),k=l=null,a.preventDefault()},document.body.appendChild(k)},{"./index":2}],2:[function(a,b){b.exports=a("./src/createOutline")},{"./src/createOutline":6}],3:[function(a,b){function c(a){this.node=a}b.exports=c},{}],4:[function(a,b){function c(a){if("HGROUP"==g.getTagName(a)){var b=a.getElementsByTagName("h"+-g.getHeadingElementRank(a));if(!b.length)return"<i>Error: no H1-H6 inside HGROUP</i>";a=b[0]}return g.escapeHtml(a.textContent)||"<i>No text content inside "+a.nodeName+"</i>"}function d(a){var b=0,c=a.getAttribute("id");if(c)return c;do c="h5o-"+ ++b;while(a.ownerDocument.getElementById(c));return a.setAttribute("id",c),c}function e(a){this.sections=[],this.startingNode=a}var f=a("./asHtml"),g=a("./utils");e.prototype={append:function(a){a.container=this,this.sections.push(a)},asHTML:function(a){if(!this.heading)throw new Error("An implied heading should have been created at some point, but wasn't.");var b=this.heading.implied?"<i>Untitled "+g.getTagName(this.startingNode)+"</i>":c(this.heading);return a&&(b='<a href="#'+d(this.startingNode)+'">'+b+"</a>"),b+f(this.sections,a)}},b.exports=e},{"./asHtml":5,"./utils":7}],5:[function(a,b){b.exports=function(a,b){for(var c="",d=0;d<a.length;d++)c+="<li>"+a[d].asHTML(b)+"</li>";return""==c?c:"<ol>"+c+"</ol>"}},{}],6:[function(a,b){function c(a){return a[a.length-1]}function d(a){if(!p.isHeading(a.heading))throw new Exception("What is the heading rank of an implied heading? Is this code even reachable?");return p.getHeadingElementRank(a.heading)}function e(){var a=c(k);return a?a.node:void 0}function f(a){var b=e();if(!p.isHeading(b)&&!p.hasHiddenAttribute(b)){if(p.hasHiddenAttribute(a))return void k.push({node:a});if(p.isSecContent(a))return null!=i&&(j.heading||(j.heading={implied:!0}),k.push(i)),i=new m(a),j=new l(a),void(i.outline={sections:[j],startingNode:a,asHTML:function(a){return n(this.sections,a)}});if(p.isSecRoot(a))return null!=i&&k.push(i),i=new m(a),i.parentSection=j,j=new l(a),void(i.outline={sections:[j],startingNode:a,asHTML:function(a){return n(this.sections,a)}});if(p.isHeading(a)){if(j.heading)if(c(i.outline.sections).heading.implied||p.getHeadingElementRank(a)>=d(c(i.outline.sections))){var f=new l(a);i.outline.sections.push(f),j=f,j.heading=a}else{var g=!1,h=j;do{if(p.getHeadingElementRank(a)<d(h)){var f=new l(a);h.append(f),j=f,j.heading=a,g=!0}var o=h.container;h=o}while(!g)}else j.heading=a;return void k.push({node:a})}}}function g(a){var b=e();if(b===a&&k.pop(),!p.isHeading(b)&&!p.hasHiddenAttribute(b)){if(!(p.isSecContent(a)&&k.length>0))return p.isSecRoot(a)&&k.length>0?(j.heading||(j.heading={implied:!0}),j=i.parentSection,void(i=k.pop())):p.isSecContent(a)||p.isSecRoot(a)?void(j.heading||(j.heading={implied:!0})):void 0;j.heading||(j.heading={implied:!0});var d=i;i=k.pop(),j=c(i.outline.sections);for(var f=0;f<d.outline.sections.length;f++)j.append(d.outline.sections[f])}}function h(a){if(!p.isSecContent(a)&&!p.isSecRoot(a))throw new TypeError("Invalid argument: start element must either be sectioning root or sectioning content.");return i=null,j=null,k=[],o(a,f,g),i.outline}var i,j,k,l=a("./Section"),m=a("./OutlineTarget"),n=a("./asHtml"),o=a("./walk"),p=a("./utils");b.exports=h},{"./OutlineTarget":3,"./Section":4,"./asHtml":5,"./utils":7,"./walk":8}],7:[function(a,b,c){function d(a){return a.tagName.toUpperCase()}function e(a){return function(b){return f(b)&&new RegExp(a,"i").test(d(b))}}function f(a){return a&&a.tagName}function g(a){var b=d(a);if("HGROUP"==b){for(var c=1;6>=c;c++)if(a.getElementsByTagName("H"+c).length>0)return-c;return-1}return-parseInt(b.substr(1))}function h(a){return(""+a).replace(/&/g,"&amp;").replace(/</g,"&lt;")}function i(a){return f(a)&&a.hasAttribute("hidden")}c.getTagName=d,c.hasHiddenAttribute=i,c.isSecRoot=e("^BLOCKQUOTE|BODY|DETAILS|FIELDSET|FIGURE|TD$"),c.isSecContent=e("^ARTICLE|ASIDE|NAV|SECTION$"),c.isHeading=e("^H[1-6]|HGROUP$"),c.getHeadingElementRank=g,c.escapeHtml=h},{}],8:[function(a,b){b.exports=function(a,b,c){var d=a;a:for(;d;)if(b(d),d.firstChild)d=d.firstChild;else for(;d;){if(c(d),d.nextSibling){d=d.nextSibling;continue a}d=d==a?null:d.parentNode}}},{}]},{},[1]);
!function a(b,c,d){function e(g,h){if(!c[g]){if(!b[g]){var i="function"==typeof require&&require;if(!h&&i)return i(g,!0);if(f)return f(g,!0);var j=new Error("Cannot find module '"+g+"'");throw j.code="MODULE_NOT_FOUND",j}var k=c[g]={exports:{}};b[g][0].call(k.exports,function(a){var c=b[g][1][a];return e(c?c:a)},k,k.exports,a,b,c,d)}return c[g].exports}for(var f="function"==typeof require&&require,g=0;g<d.length;g++)e(d[g]);return e}({1:[function(a){var b=a("./index"),c=function(a,b){for(var c=0;c<a.length;c++)a[c].setAttribute("style",b)},d="font-size:11px;font-family:Verdana, sans-serif;",e="position:fixed;top:10px;right:10px;border:2px solid #000;background:rgba(255,255,255,.9);padding:15px;z-index:999;max-height:400px;overflow:auto;",f="list-style:decimal outside;margin-left:20px;",g="margin: 0;padding:0;",h="color:#008;text-decoration:underline;",i="float: right; margin: 0 0 5px 5px; padding: 5px; border: 1px #008 solid;color:#00f;background-color:#ccf;",j=b(document.body).asHTML(!0),k=document.createElement("div");c([k],e+d),k.innerHTML=j,c(k.getElementsByTagName("li"),f+d),c(k.getElementsByTagName("ol"),g+d),c(k.getElementsByTagName("a"),h+d);var l=k.insertBefore(document.createElement("a"),k.firstChild);c([l],i),l.innerHTML="Close",l.href="#",l.onclick=function(a){document.body.removeChild(k),k=l=null,a.preventDefault()},document.body.appendChild(k)},{"./index":2}],2:[function(a,b){b.exports=a("./src/createOutline")},{"./src/createOutline":7}],3:[function(a,b){function c(a,b){this.startingNode=a.node,this.sections=[b]}var d=a("./asHTML");c.prototype.getLastSection=function(){return this.sections[this.sections.length-1]},c.prototype.asHTML=function(a){return d(this.sections,a)},b.exports=c},{"./asHTML":6}],4:[function(a,b){function c(a){this.node=a}b.exports=c},{}],5:[function(a,b){function c(a){if("HGROUP"==g.getTagName(a)){var b=a.getElementsByTagName("h"+-g.getHeadingElementRank(a));if(!b.length)return"<i>Error: no H1-H6 inside HGROUP</i>";a=b[0]}return g.escapeHtml(a.textContent)||"<i>No text content inside "+a.nodeName+"</i>"}function d(a){var b=0,c=a.getAttribute("id");if(c)return c;do c="h5o-"+ ++b;while(a.ownerDocument.getElementById(c));return a.setAttribute("id",c),c}function e(a){this.sections=[],this.startingNode=a}var f=a("./asHTML"),g=a("./utils");e.prototype.append=function(a){a.container=this,this.sections.push(a)},e.prototype.asHTML=function(a){if(!this.heading)throw new Error("An implied heading should have been created at some point, but wasn't.");var b=this.heading.implied?"<i>Untitled "+g.getTagName(this.startingNode)+"</i>":c(this.heading);return a&&(b='<a href="#'+d(this.startingNode)+'">'+b+"</a>"),b+f(this.sections,a)},b.exports=e},{"./asHTML":6,"./utils":8}],6:[function(a,b){function c(a,b){for(var c="",d=0;d<a.length;d++)c+="<li>"+a[d].asHTML(b)+"</li>";return""==c?c:"<ol>"+c+"</ol>"}b.exports=c},{}],7:[function(a,b){function c(){return i.length?i[i.length-1].node:void 0}function d(a){var b=c();if(!n.isHeading(b)&&!n.hasHiddenAttribute(b)){if(n.hasHiddenAttribute(a))return void i.push({node:a});if(n.isSecContent(a))return null!=g&&(h.heading||(h.heading={implied:!0}),i.push(g)),g=new l(a),h=new j(a),void(g.outline=new k(g.node,h));if(n.isSecRoot(a))return null!=g&&i.push(g),g=new l(a),g.parentSection=h,h=new j(a),void(g.outline=new k(g.node,h));if(n.isHeading(a)){if(h.heading)if(g.outline.getLastSection().heading.implied||n.getHeadingElementRank(a)>=n.getHeadingElementRank(g.outline.getLastSection().heading)){var d=new j(a);g.outline.sections.push(d),h=d,h.heading=a}else{var e=!1,f=h;do{if(n.getHeadingElementRank(a)<n.getHeadingElementRank(f.heading)){var d=new j(a);f.append(d),h=d,h.heading=a,e=!0}var m=f.container;f=m}while(!e)}else h.heading=a;return void i.push({node:a})}}}function e(a){var b=c();if(b===a&&i.pop(),!n.isHeading(b)&&!n.hasHiddenAttribute(b)){if(!(n.isSecContent(a)&&i.length>0))return n.isSecRoot(a)&&i.length>0?(h.heading||(h.heading={implied:!0}),h=g.parentSection,void(g=i.pop())):n.isSecContent(a)||n.isSecRoot(a)?void(h.heading||(h.heading={implied:!0})):void 0;h.heading||(h.heading={implied:!0});var d=g;g=i.pop(),h=g.outline.getLastSection();for(var e=0;e<d.outline.sections.length;e++)h.append(d.outline.sections[e])}}function f(a){if(!n.isSecContent(a)&&!n.isSecRoot(a))throw new TypeError("Invalid argument: start element must either be sectioning root or sectioning content.");return g=null,h=null,i=[],m(a,d,e),g.outline}var g,h,i,j=a("./Section"),k=a("./Outline"),l=a("./OutlineTarget"),m=a("./walk"),n=a("./utils");b.exports=f},{"./Outline":3,"./OutlineTarget":4,"./Section":5,"./utils":8,"./walk":9}],8:[function(a,b,c){function d(a){return a.tagName.toUpperCase()}function e(a){return function(b){return f(b)&&new RegExp(a,"i").test(d(b))}}function f(a){return a&&a.tagName}function g(a){var b=d(a);if("HGROUP"==b){for(var c=1;6>=c;c++)if(a.getElementsByTagName("H"+c).length>0)return-c;return-1}return-parseInt(b.substr(1))}function h(a){return(""+a).replace(/&/g,"&amp;").replace(/</g,"&lt;")}function i(a){return f(a)&&a.hasAttribute("hidden")}c.getTagName=d,c.hasHiddenAttribute=i,c.isSecRoot=e("^BLOCKQUOTE|BODY|DETAILS|FIELDSET|FIGURE|TD$"),c.isSecContent=e("^ARTICLE|ASIDE|NAV|SECTION$"),c.isHeading=e("^H[1-6]|HGROUP$"),c.getHeadingElementRank=g,c.escapeHtml=h},{}],9:[function(a,b){b.exports=function(a,b,c){var d=a;a:for(;d;)if(b(d),d.firstChild)d=d.firstChild;else for(;d;){if(c(d),d.nextSibling){d=d.nextSibling;continue a}d=d==a?null:d.parentNode}}},{}]},{},[1]);

@@ -15,3 +15,21 @@ /**

},{"./src/createOutline":5}],2:[function(require,module,exports){
},{"./src/createOutline":6}],2:[function(require,module,exports){
var asHTML = require("./asHTML");
function Outline(outlineTarget, onlySection) {
this.startingNode = outlineTarget.node;
this.sections = [onlySection];
}
Outline.prototype.getLastSection = function () {
return this.sections[this.sections.length - 1];
};
Outline.prototype.asHTML = function (createLinks) {
return asHTML(this.sections, createLinks);
};
module.exports = Outline;
},{"./asHTML":5}],3:[function(require,module,exports){
/**

@@ -30,4 +48,4 @@ * Internal data structure to avoid adding properties onto native objects

},{}],3:[function(require,module,exports){
var asHtml = require("./asHtml"),
},{}],4:[function(require,module,exports){
var asHTML = require("./asHTML"),
utils = require("./utils");

@@ -65,28 +83,26 @@

Section.prototype = {
Section.prototype.append = function (what) {
what.container = this;
this.sections.push(what);
};
append: function (what) {
what.container = this;
this.sections.push(what);
},
asHTML: function (createLinks) {
// @todo: this really belongs in a separate formatter type thing
Section.prototype.asHTML = function (createLinks) {
// @todo: this really belongs in a separate formatter type thing
if (!this.heading) {
// @todo: find formal proof if this is possible/not-possible
throw new Error("An implied heading should have been created at some point, but wasn't.");
}
if (!this.heading) {
// @todo: find formal proof if this is possible/not-possible
throw new Error("An implied heading should have been created at some point, but wasn't.");
}
var headingText = this.heading.implied
? "<i>Untitled " + utils.getTagName(this.startingNode) + "</i>"
: sectionHeadingText(this.heading);
var headingText = this.heading.implied
? "<i>Untitled " + utils.getTagName(this.startingNode) + "</i>"
: sectionHeadingText(this.heading);
if (createLinks) {
headingText = '<a href="#' + generateId(this.startingNode) + '">'
+ headingText
+ '</a>';
}
return headingText + asHtml(this.sections, createLinks);
if (createLinks) {
headingText = '<a href="#' + generateId(this.startingNode) + '">'
+ headingText
+ '</a>';
}
return headingText + asHTML(this.sections, createLinks);
};

@@ -96,4 +112,4 @@

},{"./asHtml":4,"./utils":6}],4:[function(require,module,exports){
module.exports = function (sections, createLinks) {
},{"./asHTML":5,"./utils":7}],5:[function(require,module,exports){
function asHTML(sections, createLinks) {
var retval = '';

@@ -106,28 +122,18 @@

return (retval == '' ? retval : '<ol>' + retval + '</ol>');
};
}
},{}],5:[function(require,module,exports){
module.exports = asHTML;
},{}],6:[function(require,module,exports){
var Section = require("./Section"),
Outline = require("./Outline"),
OutlineTarget = require("./OutlineTarget"),
asHtml = require("./asHtml"),
walk = require("./walk"),
utils = require("./utils");
function arrayLast(arr) {
return arr[arr.length - 1];
}
function getSectionHeadingRank(section) {
if (!utils.isHeading(section.heading)) {
// @todo: find formal proof if this is possible/not-possible
throw new Exception("What is the heading rank of an implied heading? Is this code even reachable?")
}
return utils.getHeadingElementRank(section.heading);
}
var currentOutlineTarget, currentSection, stack;
function stackTopNode() {
var top = arrayLast(stack);
return top ? top.node : undefined;
if (!stack.length) return;
return stack[stack.length - 1].node;
}

@@ -177,10 +183,3 @@

// as the only section in the outline.
// @todo: extract this into a new Outline()?
currentOutlineTarget.outline = {
sections: [currentSection],
startingNode: node,
asHTML: function (createLinks) {
return asHtml(this.sections, createLinks);
}
};
currentOutlineTarget.outline = new Outline(currentOutlineTarget.node, currentSection);
return;

@@ -209,10 +208,3 @@ }

// as the only section in the outline.
// @todo: extract this into a new Outline()?
currentOutlineTarget.outline = {
sections: [currentSection],
startingNode: node,
asHTML: function (createLinks) {
return asHtml(this.sections, createLinks);
}
};
currentOutlineTarget.outline = new Outline(currentOutlineTarget.node, currentSection);
return;

@@ -231,3 +223,3 @@ }

// outline target is an implied heading, then
} else if (arrayLast(currentOutlineTarget.outline.sections).heading.implied || utils.getHeadingElementRank(node) >= getSectionHeadingRank(arrayLast(currentOutlineTarget.outline.sections))) {
} else if (currentOutlineTarget.outline.getLastSection().heading.implied || utils.getHeadingElementRank(node) >= utils.getHeadingElementRank(currentOutlineTarget.outline.getLastSection().heading)) {

@@ -257,4 +249,18 @@ // create a new section and

do {
// note:
// if candidateSection is still currentSection - it definitely has a heading, because otherwise
// `node`, which is a heading, would be a heading for that section
// if the heading for currentSection is higher (or same), e.g. `node` is H2 and currentSection.heading is H1
// then our `node` creates a subsection and we don't need to care about anything else
// if our `node` is actually higher, e.g. `node` is H3, and currentSection.heading is H4
// H4 is not the last child of the outline target [and therefore not the only child]
// therefore there must exist an element of at least H3 or higher rank
// that is the outline parent of the H4 and that element of H3 or higher
// would then be hit by going upwards
// therefore getSectionHeadingRank is sure that candidateSection.heading is not implied
// If the element being entered has a rank lower than the rank of the heading of the candidate section, then
if (utils.getHeadingElementRank(node) < getSectionHeadingRank(candidateSection)) {
if (utils.getHeadingElementRank(node) < utils.getHeadingElementRank(candidateSection.heading)) {

@@ -327,3 +333,3 @@ // create a new section,

// Let current section be the last section in the outline of the current outline target element.
currentSection = arrayLast(currentOutlineTarget.outline.sections);
currentSection = currentOutlineTarget.outline.getLastSection();

@@ -407,3 +413,3 @@ // Append the outline of the sectioning content element being exited to the current section.

},{"./OutlineTarget":2,"./Section":3,"./asHtml":4,"./utils":6,"./walk":7}],6:[function(require,module,exports){
},{"./Outline":2,"./OutlineTarget":3,"./Section":4,"./utils":7,"./walk":8}],7:[function(require,module,exports){
function getTagName(el) {

@@ -456,3 +462,3 @@ return el.tagName.toUpperCase(); // upper casing due to http://ejohn.org/blog/nodename-case-sensitivity/

},{}],7:[function(require,module,exports){
},{}],8:[function(require,module,exports){
module.exports = function (root, enter, exit) {

@@ -459,0 +465,0 @@ var node = root;

@@ -11,2 +11,2 @@ /**

*/
!function(a){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=a();else if("function"==typeof define&&define.amd)define([],a);else{var b;b="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this,b.HTML5Outline=a()}}(function(){return function a(b,c,d){function e(g,h){if(!c[g]){if(!b[g]){var i="function"==typeof require&&require;if(!h&&i)return i(g,!0);if(f)return f(g,!0);var j=new Error("Cannot find module '"+g+"'");throw j.code="MODULE_NOT_FOUND",j}var k=c[g]={exports:{}};b[g][0].call(k.exports,function(a){var c=b[g][1][a];return e(c?c:a)},k,k.exports,a,b,c,d)}return c[g].exports}for(var f="function"==typeof require&&require,g=0;g<d.length;g++)e(d[g]);return e}({1:[function(a,b){b.exports=a("./src/createOutline")},{"./src/createOutline":5}],2:[function(a,b){function c(a){this.node=a}b.exports=c},{}],3:[function(a,b){function c(a){if("HGROUP"==g.getTagName(a)){var b=a.getElementsByTagName("h"+-g.getHeadingElementRank(a));if(!b.length)return"<i>Error: no H1-H6 inside HGROUP</i>";a=b[0]}return g.escapeHtml(a.textContent)||"<i>No text content inside "+a.nodeName+"</i>"}function d(a){var b=0,c=a.getAttribute("id");if(c)return c;do c="h5o-"+ ++b;while(a.ownerDocument.getElementById(c));return a.setAttribute("id",c),c}function e(a){this.sections=[],this.startingNode=a}var f=a("./asHtml"),g=a("./utils");e.prototype={append:function(a){a.container=this,this.sections.push(a)},asHTML:function(a){if(!this.heading)throw new Error("An implied heading should have been created at some point, but wasn't.");var b=this.heading.implied?"<i>Untitled "+g.getTagName(this.startingNode)+"</i>":c(this.heading);return a&&(b='<a href="#'+d(this.startingNode)+'">'+b+"</a>"),b+f(this.sections,a)}},b.exports=e},{"./asHtml":4,"./utils":6}],4:[function(a,b){b.exports=function(a,b){for(var c="",d=0;d<a.length;d++)c+="<li>"+a[d].asHTML(b)+"</li>";return""==c?c:"<ol>"+c+"</ol>"}},{}],5:[function(a,b){function c(a){return a[a.length-1]}function d(a){if(!p.isHeading(a.heading))throw new Exception("What is the heading rank of an implied heading? Is this code even reachable?");return p.getHeadingElementRank(a.heading)}function e(){var a=c(k);return a?a.node:void 0}function f(a){var b=e();if(!p.isHeading(b)&&!p.hasHiddenAttribute(b)){if(p.hasHiddenAttribute(a))return void k.push({node:a});if(p.isSecContent(a))return null!=i&&(j.heading||(j.heading={implied:!0}),k.push(i)),i=new m(a),j=new l(a),void(i.outline={sections:[j],startingNode:a,asHTML:function(a){return n(this.sections,a)}});if(p.isSecRoot(a))return null!=i&&k.push(i),i=new m(a),i.parentSection=j,j=new l(a),void(i.outline={sections:[j],startingNode:a,asHTML:function(a){return n(this.sections,a)}});if(p.isHeading(a)){if(j.heading)if(c(i.outline.sections).heading.implied||p.getHeadingElementRank(a)>=d(c(i.outline.sections))){var f=new l(a);i.outline.sections.push(f),j=f,j.heading=a}else{var g=!1,h=j;do{if(p.getHeadingElementRank(a)<d(h)){var f=new l(a);h.append(f),j=f,j.heading=a,g=!0}var o=h.container;h=o}while(!g)}else j.heading=a;return void k.push({node:a})}}}function g(a){var b=e();if(b===a&&k.pop(),!p.isHeading(b)&&!p.hasHiddenAttribute(b)){if(!(p.isSecContent(a)&&k.length>0))return p.isSecRoot(a)&&k.length>0?(j.heading||(j.heading={implied:!0}),j=i.parentSection,void(i=k.pop())):p.isSecContent(a)||p.isSecRoot(a)?void(j.heading||(j.heading={implied:!0})):void 0;j.heading||(j.heading={implied:!0});var d=i;i=k.pop(),j=c(i.outline.sections);for(var f=0;f<d.outline.sections.length;f++)j.append(d.outline.sections[f])}}function h(a){if(!p.isSecContent(a)&&!p.isSecRoot(a))throw new TypeError("Invalid argument: start element must either be sectioning root or sectioning content.");return i=null,j=null,k=[],o(a,f,g),i.outline}var i,j,k,l=a("./Section"),m=a("./OutlineTarget"),n=a("./asHtml"),o=a("./walk"),p=a("./utils");b.exports=h},{"./OutlineTarget":2,"./Section":3,"./asHtml":4,"./utils":6,"./walk":7}],6:[function(a,b,c){function d(a){return a.tagName.toUpperCase()}function e(a){return function(b){return f(b)&&new RegExp(a,"i").test(d(b))}}function f(a){return a&&a.tagName}function g(a){var b=d(a);if("HGROUP"==b){for(var c=1;6>=c;c++)if(a.getElementsByTagName("H"+c).length>0)return-c;return-1}return-parseInt(b.substr(1))}function h(a){return(""+a).replace(/&/g,"&amp;").replace(/</g,"&lt;")}function i(a){return f(a)&&a.hasAttribute("hidden")}c.getTagName=d,c.hasHiddenAttribute=i,c.isSecRoot=e("^BLOCKQUOTE|BODY|DETAILS|FIELDSET|FIGURE|TD$"),c.isSecContent=e("^ARTICLE|ASIDE|NAV|SECTION$"),c.isHeading=e("^H[1-6]|HGROUP$"),c.getHeadingElementRank=g,c.escapeHtml=h},{}],7:[function(a,b){b.exports=function(a,b,c){var d=a;a:for(;d;)if(b(d),d.firstChild)d=d.firstChild;else for(;d;){if(c(d),d.nextSibling){d=d.nextSibling;continue a}d=d==a?null:d.parentNode}}},{}]},{},[1])(1)});
!function(a){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=a();else if("function"==typeof define&&define.amd)define([],a);else{var b;b="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this,b.HTML5Outline=a()}}(function(){return function a(b,c,d){function e(g,h){if(!c[g]){if(!b[g]){var i="function"==typeof require&&require;if(!h&&i)return i(g,!0);if(f)return f(g,!0);var j=new Error("Cannot find module '"+g+"'");throw j.code="MODULE_NOT_FOUND",j}var k=c[g]={exports:{}};b[g][0].call(k.exports,function(a){var c=b[g][1][a];return e(c?c:a)},k,k.exports,a,b,c,d)}return c[g].exports}for(var f="function"==typeof require&&require,g=0;g<d.length;g++)e(d[g]);return e}({1:[function(a,b){b.exports=a("./src/createOutline")},{"./src/createOutline":6}],2:[function(a,b){function c(a,b){this.startingNode=a.node,this.sections=[b]}var d=a("./asHTML");c.prototype.getLastSection=function(){return this.sections[this.sections.length-1]},c.prototype.asHTML=function(a){return d(this.sections,a)},b.exports=c},{"./asHTML":5}],3:[function(a,b){function c(a){this.node=a}b.exports=c},{}],4:[function(a,b){function c(a){if("HGROUP"==g.getTagName(a)){var b=a.getElementsByTagName("h"+-g.getHeadingElementRank(a));if(!b.length)return"<i>Error: no H1-H6 inside HGROUP</i>";a=b[0]}return g.escapeHtml(a.textContent)||"<i>No text content inside "+a.nodeName+"</i>"}function d(a){var b=0,c=a.getAttribute("id");if(c)return c;do c="h5o-"+ ++b;while(a.ownerDocument.getElementById(c));return a.setAttribute("id",c),c}function e(a){this.sections=[],this.startingNode=a}var f=a("./asHTML"),g=a("./utils");e.prototype.append=function(a){a.container=this,this.sections.push(a)},e.prototype.asHTML=function(a){if(!this.heading)throw new Error("An implied heading should have been created at some point, but wasn't.");var b=this.heading.implied?"<i>Untitled "+g.getTagName(this.startingNode)+"</i>":c(this.heading);return a&&(b='<a href="#'+d(this.startingNode)+'">'+b+"</a>"),b+f(this.sections,a)},b.exports=e},{"./asHTML":5,"./utils":7}],5:[function(a,b){function c(a,b){for(var c="",d=0;d<a.length;d++)c+="<li>"+a[d].asHTML(b)+"</li>";return""==c?c:"<ol>"+c+"</ol>"}b.exports=c},{}],6:[function(a,b){function c(){return i.length?i[i.length-1].node:void 0}function d(a){var b=c();if(!n.isHeading(b)&&!n.hasHiddenAttribute(b)){if(n.hasHiddenAttribute(a))return void i.push({node:a});if(n.isSecContent(a))return null!=g&&(h.heading||(h.heading={implied:!0}),i.push(g)),g=new l(a),h=new j(a),void(g.outline=new k(g.node,h));if(n.isSecRoot(a))return null!=g&&i.push(g),g=new l(a),g.parentSection=h,h=new j(a),void(g.outline=new k(g.node,h));if(n.isHeading(a)){if(h.heading)if(g.outline.getLastSection().heading.implied||n.getHeadingElementRank(a)>=n.getHeadingElementRank(g.outline.getLastSection().heading)){var d=new j(a);g.outline.sections.push(d),h=d,h.heading=a}else{var e=!1,f=h;do{if(n.getHeadingElementRank(a)<n.getHeadingElementRank(f.heading)){var d=new j(a);f.append(d),h=d,h.heading=a,e=!0}var m=f.container;f=m}while(!e)}else h.heading=a;return void i.push({node:a})}}}function e(a){var b=c();if(b===a&&i.pop(),!n.isHeading(b)&&!n.hasHiddenAttribute(b)){if(!(n.isSecContent(a)&&i.length>0))return n.isSecRoot(a)&&i.length>0?(h.heading||(h.heading={implied:!0}),h=g.parentSection,void(g=i.pop())):n.isSecContent(a)||n.isSecRoot(a)?void(h.heading||(h.heading={implied:!0})):void 0;h.heading||(h.heading={implied:!0});var d=g;g=i.pop(),h=g.outline.getLastSection();for(var e=0;e<d.outline.sections.length;e++)h.append(d.outline.sections[e])}}function f(a){if(!n.isSecContent(a)&&!n.isSecRoot(a))throw new TypeError("Invalid argument: start element must either be sectioning root or sectioning content.");return g=null,h=null,i=[],m(a,d,e),g.outline}var g,h,i,j=a("./Section"),k=a("./Outline"),l=a("./OutlineTarget"),m=a("./walk"),n=a("./utils");b.exports=f},{"./Outline":2,"./OutlineTarget":3,"./Section":4,"./utils":7,"./walk":8}],7:[function(a,b,c){function d(a){return a.tagName.toUpperCase()}function e(a){return function(b){return f(b)&&new RegExp(a,"i").test(d(b))}}function f(a){return a&&a.tagName}function g(a){var b=d(a);if("HGROUP"==b){for(var c=1;6>=c;c++)if(a.getElementsByTagName("H"+c).length>0)return-c;return-1}return-parseInt(b.substr(1))}function h(a){return(""+a).replace(/&/g,"&amp;").replace(/</g,"&lt;")}function i(a){return f(a)&&a.hasAttribute("hidden")}c.getTagName=d,c.hasHiddenAttribute=i,c.isSecRoot=e("^BLOCKQUOTE|BODY|DETAILS|FIELDSET|FIGURE|TD$"),c.isSecContent=e("^ARTICLE|ASIDE|NAV|SECTION$"),c.isHeading=e("^H[1-6]|HGROUP$"),c.getHeadingElementRank=g,c.escapeHtml=h},{}],8:[function(a,b){b.exports=function(a,b,c){var d=a;a:for(;d;)if(b(d),d.firstChild)d=d.firstChild;else for(;d;){if(c(d),d.nextSibling){d=d.nextSibling;continue a}d=d==a?null:d.parentNode}}},{}]},{},[1])(1)});
{
"name": "h5o",
"version": "0.9.2",
"version": "0.9.3",
"description": "HTML5 outliner",

@@ -41,3 +41,4 @@ "main": "index.js",

"grunt-saucelabs": "8.x",
"jsdom": "3.x",
"jsdom": "4.x",
"jsdom-compat": "1.x",
"load-grunt-tasks": "3.x",

@@ -44,0 +45,0 @@ "phantomjs": "1.9.x",

@@ -6,3 +6,6 @@ # HTML5 outliner #

![Supported: node v0.12](http://img.shields.io/badge/node-0.12.x-brightgreen.svg)
![Supported: phantom.js v1.9](http://img.shields.io/badge/phantom.js-1.9.x-brightgreen.svg)
![Supported: jsdom v3.x](http://img.shields.io/badge/jsdom-3.x-brightgreen.svg)
![Supported: jsdom v4.x](http://img.shields.io/badge/jsdom-4.x-brightgreen.svg)

@@ -59,2 +62,7 @@ [![Sauce Test Status](https://saucelabs.com/browser-matrix/h5o-js.svg)](https://saucelabs.com/u/h5o-js)

### v0.9.3 (2015-03-11) ###
* `Outline` is not a separate object of its own
* `getSectionHeadingRank` cleanup
* Travis runs tests in both - `jsdom` v4.x and v3.x via [`jsdom-compat`](https://github.com/h5o/jsdom-compat)
### v0.9.2 (2015-03-07) ###

@@ -61,0 +69,0 @@ * Throw when non-sectioning root / content element passed in for outlining

var Section = require("./Section"),
Outline = require("./Outline"),
OutlineTarget = require("./OutlineTarget"),
asHtml = require("./asHtml"),
walk = require("./walk"),
utils = require("./utils");
function arrayLast(arr) {
return arr[arr.length - 1];
}
function getSectionHeadingRank(section) {
if (!utils.isHeading(section.heading)) {
// @todo: find formal proof if this is possible/not-possible
throw new Exception("What is the heading rank of an implied heading? Is this code even reachable?")
}
return utils.getHeadingElementRank(section.heading);
}
var currentOutlineTarget, currentSection, stack;
function stackTopNode() {
var top = arrayLast(stack);
return top ? top.node : undefined;
if (!stack.length) return;
return stack[stack.length - 1].node;
}

@@ -68,10 +56,3 @@

// as the only section in the outline.
// @todo: extract this into a new Outline()?
currentOutlineTarget.outline = {
sections: [currentSection],
startingNode: node,
asHTML: function (createLinks) {
return asHtml(this.sections, createLinks);
}
};
currentOutlineTarget.outline = new Outline(currentOutlineTarget.node, currentSection);
return;

@@ -100,10 +81,3 @@ }

// as the only section in the outline.
// @todo: extract this into a new Outline()?
currentOutlineTarget.outline = {
sections: [currentSection],
startingNode: node,
asHTML: function (createLinks) {
return asHtml(this.sections, createLinks);
}
};
currentOutlineTarget.outline = new Outline(currentOutlineTarget.node, currentSection);
return;

@@ -122,3 +96,3 @@ }

// outline target is an implied heading, then
} else if (arrayLast(currentOutlineTarget.outline.sections).heading.implied || utils.getHeadingElementRank(node) >= getSectionHeadingRank(arrayLast(currentOutlineTarget.outline.sections))) {
} else if (currentOutlineTarget.outline.getLastSection().heading.implied || utils.getHeadingElementRank(node) >= utils.getHeadingElementRank(currentOutlineTarget.outline.getLastSection().heading)) {

@@ -148,4 +122,18 @@ // create a new section and

do {
// note:
// if candidateSection is still currentSection - it definitely has a heading, because otherwise
// `node`, which is a heading, would be a heading for that section
// if the heading for currentSection is higher (or same), e.g. `node` is H2 and currentSection.heading is H1
// then our `node` creates a subsection and we don't need to care about anything else
// if our `node` is actually higher, e.g. `node` is H3, and currentSection.heading is H4
// H4 is not the last child of the outline target [and therefore not the only child]
// therefore there must exist an element of at least H3 or higher rank
// that is the outline parent of the H4 and that element of H3 or higher
// would then be hit by going upwards
// therefore getSectionHeadingRank is sure that candidateSection.heading is not implied
// If the element being entered has a rank lower than the rank of the heading of the candidate section, then
if (utils.getHeadingElementRank(node) < getSectionHeadingRank(candidateSection)) {
if (utils.getHeadingElementRank(node) < utils.getHeadingElementRank(candidateSection.heading)) {

@@ -218,3 +206,3 @@ // create a new section,

// Let current section be the last section in the outline of the current outline target element.
currentSection = arrayLast(currentOutlineTarget.outline.sections);
currentSection = currentOutlineTarget.outline.getLastSection();

@@ -221,0 +209,0 @@ // Append the outline of the sectioning content element being exited to the current section.

@@ -1,2 +0,2 @@

var asHtml = require("./asHtml"),
var asHTML = require("./asHTML"),
utils = require("./utils");

@@ -34,30 +34,28 @@

Section.prototype = {
Section.prototype.append = function (what) {
what.container = this;
this.sections.push(what);
};
append: function (what) {
what.container = this;
this.sections.push(what);
},
asHTML: function (createLinks) {
// @todo: this really belongs in a separate formatter type thing
Section.prototype.asHTML = function (createLinks) {
// @todo: this really belongs in a separate formatter type thing
if (!this.heading) {
// @todo: find formal proof if this is possible/not-possible
throw new Error("An implied heading should have been created at some point, but wasn't.");
}
if (!this.heading) {
// @todo: find formal proof if this is possible/not-possible
throw new Error("An implied heading should have been created at some point, but wasn't.");
}
var headingText = this.heading.implied
? "<i>Untitled " + utils.getTagName(this.startingNode) + "</i>"
: sectionHeadingText(this.heading);
var headingText = this.heading.implied
? "<i>Untitled " + utils.getTagName(this.startingNode) + "</i>"
: sectionHeadingText(this.heading);
if (createLinks) {
headingText = '<a href="#' + generateId(this.startingNode) + '">'
+ headingText
+ '</a>';
}
return headingText + asHtml(this.sections, createLinks);
if (createLinks) {
headingText = '<a href="#' + generateId(this.startingNode) + '">'
+ headingText
+ '</a>';
}
return headingText + asHTML(this.sections, createLinks);
};
module.exports = Section;

@@ -1,7 +0,3 @@

(function () {
function createTests(suffix, doc, contextPath, HTML5Outline) {
var doc = this.document || this.jsdomDocument;
var contextPath = this.contextPath || buster.env.contextPath || "";
var expect = buster.referee.expect,

@@ -16,3 +12,3 @@ describe = buster.spec.describe,

describe('h5o', function () {
describe('h5o.' + suffix, function () {

@@ -88,2 +84,10 @@ before(function () {

});
}());
}
if (typeof(window) === "undefined") {
// jsdom tests are created on demand in tests.jsdom.js
module.exports = createTests;
} else {
// browser tests rely on the global and autorun
createTests("browser", document, buster.env.contextPath || "", HTML5Outline);
}

@@ -1,17 +0,16 @@

buster = require("buster");
global.buster = require("buster");
var createTests = require("./tests");
var HTML5Outline = require("../dist/outliner.min");
var contextPath = require("path").resolve(__dirname + "/..");
require("jsdom")
.env("<div></div>", {
features: {
FetchExternalResources: ["iframe"]
}
}, function (e, w) {
function runTestsIn(jsdomModule) {
require(jsdomModule).env(
"<div></div>",
{features: {FetchExternalResources: ["iframe"]}},
function (e, w) {
createTests(jsdomModule, w.document, contextPath, HTML5Outline);
});
}
jsdomDocument = w.document;
contextPath = require("path").resolve(__dirname + "/..");
// @todo: tests still rely on a global being present
global.HTML5Outline = require("../dist/outliner.min");
require("./tests");
});
runTestsIn("jsdom-compat");
!process.version.indexOf("v0.10") || runTestsIn("jsdom");

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