Comparing version 0.8.0 to 0.9.0
@@ -59,6 +59,7 @@ /** | ||
function getSectionHeadingRank(section) { | ||
var heading = section.heading; | ||
return utils.isHeading(heading) | ||
? utils.getHeadingElementRank(heading) | ||
: 1; // @todo: as our ranks are negative, this is waaaay incorrect | ||
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); | ||
} | ||
@@ -92,3 +93,5 @@ | ||
// current section. | ||
// @todo | ||
if (!currentSection.heading) { | ||
currentSection.heading = {implied: true}; | ||
} | ||
@@ -158,7 +161,6 @@ // Push current outline target onto the stack. | ||
// Otherwise, if the element being entered has a rank equal to or higher than the heading of the last section of | ||
// the outline of the current outline target, or if the heading of the last section of the outline of the current | ||
// outline target is an implied heading, then | ||
// @todo: fix getSectionHeadingRank to not return 1 | ||
} else if (utils.getHeadingElementRank(node) >= getSectionHeadingRank(arrayLast(currentOutlineTarget.outline.sections)) || !arrayLast(currentOutlineTarget.outline.sections).heading) { | ||
// Otherwise, if the element being entered has a rank equal to or higher than the heading of the last section of | ||
// the outline of the current outline target, or if the heading of the last section of the outline of the current | ||
// outline target is an implied heading, then | ||
} else if (arrayLast(currentOutlineTarget.outline.sections).heading.implied || utils.getHeadingElementRank(node) >= getSectionHeadingRank(arrayLast(currentOutlineTarget.outline.sections))) { | ||
@@ -178,3 +180,3 @@ // create a new section and | ||
// Otherwise, run these substeps: | ||
// Otherwise, run these substeps: | ||
} else { | ||
@@ -190,3 +192,2 @@ | ||
// If the element being entered has a rank lower than the rank of the heading of the candidate section, then | ||
// @todo: double check - can candidateSection ever not have a heading or have an implied one? | ||
if (utils.getHeadingElementRank(node) < getSectionHeadingRank(candidateSection)) { | ||
@@ -250,3 +251,5 @@ | ||
// If the current section has no heading, create an implied heading and let that be the heading for the current section. | ||
// @todo | ||
if (!currentSection.heading) { | ||
currentSection.heading = {implied: true}; | ||
} | ||
@@ -271,3 +274,5 @@ // Pop the top element from the stack, and let the current outline target be that element. | ||
// If the current section has no heading, create an implied heading and let that be the heading for the current section. | ||
// @todo | ||
if (!currentSection.heading) { | ||
currentSection.heading = {implied: true}; | ||
} | ||
@@ -288,3 +293,5 @@ // Let current section be current outline target's parent section. | ||
// If the current section has no heading, create an implied heading and let that be the heading for the current section. | ||
// @todo | ||
if (!currentSection.heading) { | ||
currentSection.heading = {implied: true}; | ||
} | ||
@@ -312,3 +319,3 @@ // Skip to the next step in the overall set of steps. (The walk is over.) | ||
// @todo: the below has changed. What if the element is not sectioning root/content? | ||
// @todo: move up the tree, to the root, until a sectioning content/sectioning root is found | ||
// Walk over the DOM in tree order, starting with the sectioning content element or sectioning root element at the | ||
@@ -362,4 +369,2 @@ // root of the subtree for which an outline is to be created, and trigger the first relevant step below for each | ||
this.startingNode = startingNode; | ||
this.heading = false; | ||
} | ||
@@ -376,6 +381,12 @@ | ||
// @todo: this really belongs in a separate formatter type thing | ||
var headingText = "<i>Untitled " + utils.getTagName(this.startingNode) + "</i>"; | ||
if (this.heading) { | ||
headingText = sectionHeadingText(this.heading); | ||
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); | ||
if (createLinks) { | ||
@@ -382,0 +393,0 @@ headingText = '<a href="#' + generateId(this.startingNode) + '">' |
@@ -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("./src/HTML5Outline"),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)},{"./src/HTML5Outline":2}],2:[function(a,b){function c(a){return a[a.length-1]}function d(a){var b=a.heading;return n.isHeading(b)?n.getHeadingElementRank(b):1}function e(a){var b=c(j);if(!n.isHeading(b)&&!n.hasHiddenAttribute(b)){if(n.hasHiddenAttribute(a))return void j.push(a);if(n.isSecContent(a))return null!=h&&j.push(h),h=a,i=new k(a),void(h.outline={sections:[i],startingNode:a,asHTML:function(a){return l(this.sections,a)}});if(n.isSecRoot(a))return null!=h&&j.push(h),h=a,h.parentSection=i,i=new k(a),void(h.outline={sections:[i],startingNode:a,asHTML:function(a){return l(this.sections,a)}});if(n.isHeading(a)){if(i.heading)if(n.getHeadingElementRank(a)>=d(c(h.outline.sections))||!c(h.outline.sections).heading){var e=new k(a);h.outline.sections.push(e),i=e,i.heading=a}else{var f=!1,g=i;do{if(n.getHeadingElementRank(a)<d(g)){var e=new k(a);g.append(e),i=e,i.heading=a,f=!0}var m=g.container;g=m}while(!f)}else i.heading=a;return void j.push(a)}}}function f(a){var b=c(j);if(b===a&&j.pop(),!n.isHeading(b)&&!n.hasHiddenAttribute(b)){if(!(n.isSecContent(a)&&j.length>0))return n.isSecRoot(a)&&j.length>0?(i=h.parentSection,void(h=j.pop())):void(n.isSecContent(a)||n.isSecRoot(a));h=j.pop(),i=c(h.outline.sections);for(var d=0;d<a.outline.sections.length;d++)i.append(a.outline.sections[d])}}function g(a){return h=null,i=null,j=[],m(a,e,f),null!=h?h.outline:null}var h,i,j,k=a("./Section"),l=a("./asHtml"),m=a("./walk"),n=a("./utils");b.exports=g},{"./Section":3,"./asHtml":4,"./utils":5,"./walk":6}],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,this.heading=!1}var f=a("./asHtml"),g=a("./utils");e.prototype={append:function(a){a.container=this,this.sections.push(a)},asHTML:function(a){var b="<i>Untitled "+g.getTagName(this.startingNode)+"</i>";return this.heading&&(b=c(this.heading)),a&&(b='<a href="#'+d(this.startingNode)+'">'+b+"</a>"),b+f(this.sections,a)}},b.exports=e},{"./asHtml":4,"./utils":5}],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,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,"&").replace(/</g,"<")}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},{}],6:[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("./src/HTML5Outline"),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)},{"./src/HTML5Outline":2}],2:[function(a,b){function c(a){return a[a.length-1]}function d(a){if(!n.isHeading(a.heading))throw new Exception("What is the heading rank of an implied heading? Is this code even reachable?");return n.getHeadingElementRank(a.heading)}function e(a){var b=c(j);if(!n.isHeading(b)&&!n.hasHiddenAttribute(b)){if(n.hasHiddenAttribute(a))return void j.push(a);if(n.isSecContent(a))return null!=h&&(i.heading||(i.heading={implied:!0}),j.push(h)),h=a,i=new k(a),void(h.outline={sections:[i],startingNode:a,asHTML:function(a){return l(this.sections,a)}});if(n.isSecRoot(a))return null!=h&&j.push(h),h=a,h.parentSection=i,i=new k(a),void(h.outline={sections:[i],startingNode:a,asHTML:function(a){return l(this.sections,a)}});if(n.isHeading(a)){if(i.heading)if(c(h.outline.sections).heading.implied||n.getHeadingElementRank(a)>=d(c(h.outline.sections))){var e=new k(a);h.outline.sections.push(e),i=e,i.heading=a}else{var f=!1,g=i;do{if(n.getHeadingElementRank(a)<d(g)){var e=new k(a);g.append(e),i=e,i.heading=a,f=!0}var m=g.container;g=m}while(!f)}else i.heading=a;return void j.push(a)}}}function f(a){var b=c(j);if(b===a&&j.pop(),!n.isHeading(b)&&!n.hasHiddenAttribute(b)){if(!(n.isSecContent(a)&&j.length>0))return n.isSecRoot(a)&&j.length>0?(i.heading||(i.heading={implied:!0}),i=h.parentSection,void(h=j.pop())):n.isSecContent(a)||n.isSecRoot(a)?void(i.heading||(i.heading={implied:!0})):void 0;i.heading||(i.heading={implied:!0}),h=j.pop(),i=c(h.outline.sections);for(var d=0;d<a.outline.sections.length;d++)i.append(a.outline.sections[d])}}function g(a){return h=null,i=null,j=[],m(a,e,f),null!=h?h.outline:null}var h,i,j,k=a("./Section"),l=a("./asHtml"),m=a("./walk"),n=a("./utils");b.exports=g},{"./Section":3,"./asHtml":4,"./utils":5,"./walk":6}],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":5}],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,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,"&").replace(/</g,"<")}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},{}],6:[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]); |
@@ -26,6 +26,7 @@ /** | ||
function getSectionHeadingRank(section) { | ||
var heading = section.heading; | ||
return utils.isHeading(heading) | ||
? utils.getHeadingElementRank(heading) | ||
: 1; // @todo: as our ranks are negative, this is waaaay incorrect | ||
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); | ||
} | ||
@@ -59,3 +60,5 @@ | ||
// current section. | ||
// @todo | ||
if (!currentSection.heading) { | ||
currentSection.heading = {implied: true}; | ||
} | ||
@@ -125,7 +128,6 @@ // Push current outline target onto the stack. | ||
// Otherwise, if the element being entered has a rank equal to or higher than the heading of the last section of | ||
// the outline of the current outline target, or if the heading of the last section of the outline of the current | ||
// outline target is an implied heading, then | ||
// @todo: fix getSectionHeadingRank to not return 1 | ||
} else if (utils.getHeadingElementRank(node) >= getSectionHeadingRank(arrayLast(currentOutlineTarget.outline.sections)) || !arrayLast(currentOutlineTarget.outline.sections).heading) { | ||
// Otherwise, if the element being entered has a rank equal to or higher than the heading of the last section of | ||
// the outline of the current outline target, or if the heading of the last section of the outline of the current | ||
// outline target is an implied heading, then | ||
} else if (arrayLast(currentOutlineTarget.outline.sections).heading.implied || utils.getHeadingElementRank(node) >= getSectionHeadingRank(arrayLast(currentOutlineTarget.outline.sections))) { | ||
@@ -145,3 +147,3 @@ // create a new section and | ||
// Otherwise, run these substeps: | ||
// Otherwise, run these substeps: | ||
} else { | ||
@@ -157,3 +159,2 @@ | ||
// If the element being entered has a rank lower than the rank of the heading of the candidate section, then | ||
// @todo: double check - can candidateSection ever not have a heading or have an implied one? | ||
if (utils.getHeadingElementRank(node) < getSectionHeadingRank(candidateSection)) { | ||
@@ -217,3 +218,5 @@ | ||
// If the current section has no heading, create an implied heading and let that be the heading for the current section. | ||
// @todo | ||
if (!currentSection.heading) { | ||
currentSection.heading = {implied: true}; | ||
} | ||
@@ -238,3 +241,5 @@ // Pop the top element from the stack, and let the current outline target be that element. | ||
// If the current section has no heading, create an implied heading and let that be the heading for the current section. | ||
// @todo | ||
if (!currentSection.heading) { | ||
currentSection.heading = {implied: true}; | ||
} | ||
@@ -255,3 +260,5 @@ // Let current section be current outline target's parent section. | ||
// If the current section has no heading, create an implied heading and let that be the heading for the current section. | ||
// @todo | ||
if (!currentSection.heading) { | ||
currentSection.heading = {implied: true}; | ||
} | ||
@@ -279,3 +286,3 @@ // Skip to the next step in the overall set of steps. (The walk is over.) | ||
// @todo: the below has changed. What if the element is not sectioning root/content? | ||
// @todo: move up the tree, to the root, until a sectioning content/sectioning root is found | ||
// Walk over the DOM in tree order, starting with the sectioning content element or sectioning root element at the | ||
@@ -329,4 +336,2 @@ // root of the subtree for which an outline is to be created, and trigger the first relevant step below for each | ||
this.startingNode = startingNode; | ||
this.heading = false; | ||
} | ||
@@ -343,6 +348,12 @@ | ||
// @todo: this really belongs in a separate formatter type thing | ||
var headingText = "<i>Untitled " + utils.getTagName(this.startingNode) + "</i>"; | ||
if (this.heading) { | ||
headingText = sectionHeadingText(this.heading); | ||
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); | ||
if (createLinks) { | ||
@@ -349,0 +360,0 @@ headingText = '<a href="#' + generateId(this.startingNode) + '">' |
@@ -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/HTML5Outline")},{"./src/HTML5Outline":2}],2:[function(a,b){function c(a){return a[a.length-1]}function d(a){var b=a.heading;return n.isHeading(b)?n.getHeadingElementRank(b):1}function e(a){var b=c(j);if(!n.isHeading(b)&&!n.hasHiddenAttribute(b)){if(n.hasHiddenAttribute(a))return void j.push(a);if(n.isSecContent(a))return null!=h&&j.push(h),h=a,i=new k(a),void(h.outline={sections:[i],startingNode:a,asHTML:function(a){return l(this.sections,a)}});if(n.isSecRoot(a))return null!=h&&j.push(h),h=a,h.parentSection=i,i=new k(a),void(h.outline={sections:[i],startingNode:a,asHTML:function(a){return l(this.sections,a)}});if(n.isHeading(a)){if(i.heading)if(n.getHeadingElementRank(a)>=d(c(h.outline.sections))||!c(h.outline.sections).heading){var e=new k(a);h.outline.sections.push(e),i=e,i.heading=a}else{var f=!1,g=i;do{if(n.getHeadingElementRank(a)<d(g)){var e=new k(a);g.append(e),i=e,i.heading=a,f=!0}var m=g.container;g=m}while(!f)}else i.heading=a;return void j.push(a)}}}function f(a){var b=c(j);if(b===a&&j.pop(),!n.isHeading(b)&&!n.hasHiddenAttribute(b)){if(!(n.isSecContent(a)&&j.length>0))return n.isSecRoot(a)&&j.length>0?(i=h.parentSection,void(h=j.pop())):void(n.isSecContent(a)||n.isSecRoot(a));h=j.pop(),i=c(h.outline.sections);for(var d=0;d<a.outline.sections.length;d++)i.append(a.outline.sections[d])}}function g(a){return h=null,i=null,j=[],m(a,e,f),null!=h?h.outline:null}var h,i,j,k=a("./Section"),l=a("./asHtml"),m=a("./walk"),n=a("./utils");b.exports=g},{"./Section":3,"./asHtml":4,"./utils":5,"./walk":6}],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,this.heading=!1}var f=a("./asHtml"),g=a("./utils");e.prototype={append:function(a){a.container=this,this.sections.push(a)},asHTML:function(a){var b="<i>Untitled "+g.getTagName(this.startingNode)+"</i>";return this.heading&&(b=c(this.heading)),a&&(b='<a href="#'+d(this.startingNode)+'">'+b+"</a>"),b+f(this.sections,a)}},b.exports=e},{"./asHtml":4,"./utils":5}],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,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,"&").replace(/</g,"<")}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},{}],6:[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/HTML5Outline")},{"./src/HTML5Outline":2}],2:[function(a,b){function c(a){return a[a.length-1]}function d(a){if(!n.isHeading(a.heading))throw new Exception("What is the heading rank of an implied heading? Is this code even reachable?");return n.getHeadingElementRank(a.heading)}function e(a){var b=c(j);if(!n.isHeading(b)&&!n.hasHiddenAttribute(b)){if(n.hasHiddenAttribute(a))return void j.push(a);if(n.isSecContent(a))return null!=h&&(i.heading||(i.heading={implied:!0}),j.push(h)),h=a,i=new k(a),void(h.outline={sections:[i],startingNode:a,asHTML:function(a){return l(this.sections,a)}});if(n.isSecRoot(a))return null!=h&&j.push(h),h=a,h.parentSection=i,i=new k(a),void(h.outline={sections:[i],startingNode:a,asHTML:function(a){return l(this.sections,a)}});if(n.isHeading(a)){if(i.heading)if(c(h.outline.sections).heading.implied||n.getHeadingElementRank(a)>=d(c(h.outline.sections))){var e=new k(a);h.outline.sections.push(e),i=e,i.heading=a}else{var f=!1,g=i;do{if(n.getHeadingElementRank(a)<d(g)){var e=new k(a);g.append(e),i=e,i.heading=a,f=!0}var m=g.container;g=m}while(!f)}else i.heading=a;return void j.push(a)}}}function f(a){var b=c(j);if(b===a&&j.pop(),!n.isHeading(b)&&!n.hasHiddenAttribute(b)){if(!(n.isSecContent(a)&&j.length>0))return n.isSecRoot(a)&&j.length>0?(i.heading||(i.heading={implied:!0}),i=h.parentSection,void(h=j.pop())):n.isSecContent(a)||n.isSecRoot(a)?void(i.heading||(i.heading={implied:!0})):void 0;i.heading||(i.heading={implied:!0}),h=j.pop(),i=c(h.outline.sections);for(var d=0;d<a.outline.sections.length;d++)i.append(a.outline.sections[d])}}function g(a){return h=null,i=null,j=[],m(a,e,f),null!=h?h.outline:null}var h,i,j,k=a("./Section"),l=a("./asHtml"),m=a("./walk"),n=a("./utils");b.exports=g},{"./Section":3,"./asHtml":4,"./utils":5,"./walk":6}],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":5}],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,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,"&").replace(/</g,"<")}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},{}],6:[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.8.0", | ||
"version": "0.9.0", | ||
"description": "HTML5 outliner", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -55,10 +55,19 @@ # HTML5 outliner # | ||
### vNext (????-??-??) ### | ||
* ??? | ||
### v0.9.0 (2015-03-02) ### | ||
* Added jsdom@4.x on io.js to the test matrix | ||
* Fixed implied headings to follow the spec - this actually means the previous implementation was | ||
incorrect - updated the following tests: `navfirst`, `issue-13`. Issue #13 was partly invalid. | ||
* Added more examples from the spec | ||
### v0.8.0 (2015-03-01) ### | ||
* Updating to the latest specified algorithm | ||
* Updated to the latest specified algorithm | ||
* Fixed #11: HTML entity escaping | ||
* Fixed #13: problems with sectioning root elements inside the outline | ||
* Handling of `hgroup` without any `h1`-`h6` inside | ||
* Properly handling of `hgroup` without any `h1`-`h6` inside | ||
### v0.7.5 (2015-02-26) ### | ||
* Renaming `grunt start-dev` in favor a simpler `grunt watch` | ||
* Renamed `grunt start-dev` in favor a simpler `grunt watch` | ||
* Bookmarklet now goes via browserify | ||
@@ -84,7 +93,7 @@ * Bookmarklet works in Firefox again (fixes #6) | ||
* Using browserify instead of concatenation | ||
* Making tests pass with jsdom | ||
* Updating browsers and dependencies | ||
* Made tests pass with `jsdom` | ||
* Updated browsers and dependencies | ||
### v0.6.3 (2014-06-06) ### | ||
* Replacing inter with buster | ||
* Replaced intern with buster | ||
@@ -91,0 +100,0 @@ ### v0.6.2 (2014-06-05) ### |
@@ -11,6 +11,7 @@ var Section = require("./Section"), | ||
function getSectionHeadingRank(section) { | ||
var heading = section.heading; | ||
return utils.isHeading(heading) | ||
? utils.getHeadingElementRank(heading) | ||
: 1; // @todo: as our ranks are negative, this is waaaay incorrect | ||
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); | ||
} | ||
@@ -44,3 +45,5 @@ | ||
// current section. | ||
// @todo | ||
if (!currentSection.heading) { | ||
currentSection.heading = {implied: true}; | ||
} | ||
@@ -110,7 +113,6 @@ // Push current outline target onto the stack. | ||
// Otherwise, if the element being entered has a rank equal to or higher than the heading of the last section of | ||
// the outline of the current outline target, or if the heading of the last section of the outline of the current | ||
// outline target is an implied heading, then | ||
// @todo: fix getSectionHeadingRank to not return 1 | ||
} else if (utils.getHeadingElementRank(node) >= getSectionHeadingRank(arrayLast(currentOutlineTarget.outline.sections)) || !arrayLast(currentOutlineTarget.outline.sections).heading) { | ||
// Otherwise, if the element being entered has a rank equal to or higher than the heading of the last section of | ||
// the outline of the current outline target, or if the heading of the last section of the outline of the current | ||
// outline target is an implied heading, then | ||
} else if (arrayLast(currentOutlineTarget.outline.sections).heading.implied || utils.getHeadingElementRank(node) >= getSectionHeadingRank(arrayLast(currentOutlineTarget.outline.sections))) { | ||
@@ -130,3 +132,3 @@ // create a new section and | ||
// Otherwise, run these substeps: | ||
// Otherwise, run these substeps: | ||
} else { | ||
@@ -142,3 +144,2 @@ | ||
// If the element being entered has a rank lower than the rank of the heading of the candidate section, then | ||
// @todo: double check - can candidateSection ever not have a heading or have an implied one? | ||
if (utils.getHeadingElementRank(node) < getSectionHeadingRank(candidateSection)) { | ||
@@ -202,3 +203,5 @@ | ||
// If the current section has no heading, create an implied heading and let that be the heading for the current section. | ||
// @todo | ||
if (!currentSection.heading) { | ||
currentSection.heading = {implied: true}; | ||
} | ||
@@ -223,3 +226,5 @@ // Pop the top element from the stack, and let the current outline target be that element. | ||
// If the current section has no heading, create an implied heading and let that be the heading for the current section. | ||
// @todo | ||
if (!currentSection.heading) { | ||
currentSection.heading = {implied: true}; | ||
} | ||
@@ -240,3 +245,5 @@ // Let current section be current outline target's parent section. | ||
// If the current section has no heading, create an implied heading and let that be the heading for the current section. | ||
// @todo | ||
if (!currentSection.heading) { | ||
currentSection.heading = {implied: true}; | ||
} | ||
@@ -264,3 +271,3 @@ // Skip to the next step in the overall set of steps. (The walk is over.) | ||
// @todo: the below has changed. What if the element is not sectioning root/content? | ||
// @todo: move up the tree, to the root, until a sectioning content/sectioning root is found | ||
// Walk over the DOM in tree order, starting with the sectioning content element or sectioning root element at the | ||
@@ -267,0 +274,0 @@ // root of the subtree for which an outline is to be created, and trigger the first relevant step below for each |
@@ -32,4 +32,2 @@ var asHtml = require("./asHtml"), | ||
this.startingNode = startingNode; | ||
this.heading = false; | ||
} | ||
@@ -46,6 +44,12 @@ | ||
// @todo: this really belongs in a separate formatter type thing | ||
var headingText = "<i>Untitled " + utils.getTagName(this.startingNode) + "</i>"; | ||
if (this.heading) { | ||
headingText = sectionHeadingText(this.heading); | ||
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); | ||
if (createLinks) { | ||
@@ -52,0 +56,0 @@ headingText = '<a href="#' + generateId(this.startingNode) + '">' |
@@ -23,5 +23,11 @@ (function () { | ||
var iframeTestList = [ | ||
"spec1", "spec2", "spec3a", "spec3b", "spec4", "navfirst", | ||
"spec1", "spec2", "spec3a", "spec3b", "spec4", | ||
"spec5", "spec6", "spec7", "spec8", | ||
"navfirst", "blockquote", | ||
"links_simple", "links_idreuse", "links_idcollision", | ||
"hgroup", "hgroup-without-headings", "hgroup-with-h1", | ||
"issue-11", "issue-13" | ||
@@ -28,0 +34,0 @@ ]; |
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
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
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
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
128761
62
1371
116