HTML5 Outliner bookmarklet (v0.4.36) for IE (Internet Explorer) | UA - User Agents
Standards Based Development
Drag this link to your favorites bar:
H5O v0.4.36
Note: If the page is using HTML5, the latest version of html5.js should be running on it (some earlier versions were not did not include hgroup), otherwise the results are quite unpredictable and you may see some JS errors.
In the foreseeable future, it is unlikely that IE support of H5O will be improved - for reasons please visit ProblemsWithInternetExplorer wiki page.
/** * This code contains an implementation of HTML5 outlining algorithm, as described by WHATWG at [1] * * The copyright notice at [2] says: * (c) Copyright 2004-2009 Apple Computer, Inc., Mozilla Foundation, and Opera Software ASA. * You are granted a license to use, reproduce and create derivative works of this document. * * [1] http://www.whatwg.org/specs/web-apps/current-work/multipage/sections.html#outlines * [2] http://www.whatwg.org/specs/web-apps/current-work/multipage/index.html */
Bookmarklet JavaScript:
javascript:(
function(){
var h=function(){
this.sections=[]};h.prototype={heading:false,append:function(a){a.container=this;this.sections.push(a)},asHTML:function(){return s(this.heading)+q(this.sections)}};
var q=function(a){
for(
var b="",f=0;f<a.length;f++)b+="<li>"+a[f].asHTML()+"</li>";
return b==""?b:"<ol>"+b+"</ol>"},r=function(a){a=a.heading;return i(a)?j(a):1},s=function(a){if(i(a)){if(k(a)=="HGROUP")a=a.getElementsByTagName("h"+-j(a))[0];
return a.textContent||a.innerText||a.innerHTML}return""+a},d,c,g,t=
function(a,b,f){
var e=a;a:for(;e;){b(e);
if(e.firstChild){e=e.firstChild;continue a}for(;e;){f(e);
if(e.nextSibling){e=e.nextSibling;continue a}e=e==a?null:e.parentNode}}},u=function(a){if(!i(o(g)))if(l(a)||m(a)){d!=null&&g.push(d);d=a;c=new h;d.outline={sections:[c],asHTML:function(){return q(this.sections)}}}else if(d!=null)if(i(a)){if(c.heading)if(j(a)>=r(n(d.outline)))
{
var b=new h;d.outline.sections.push(b);
c=b;c.heading=a}else{b=false;
var f=c;
do{if(j(a)<r(f)){b=new h;
f.append(b);
c=b;
c.heading=a;
b=true}
f=f.container}while(!b)}else c.heading=a;g.push(a)}},v=function(a){var b=o(g);if(i(b))b==a&&g.pop();
else{if((l(a)||m(a))&&!c.heading)c.heading="<i>Untitled "+k(a)+"</i>";if(l(a)&&g.length>0){d=g.pop();c=n(d.outline);
for(b=0;b<a.outline.sections.length;b++)c.append(a.outline.sections[b])}else if(m(a)&&g.length>0){d=g.pop();
for(c=n(d.outline);c.sections.length>0;)c=n(c)}else if(l(a)||m(a))c=d.outline.sections[0]}},k=function(a){return a.tagName.toUpperCase()},p=function(a){return function(b){return w(b)&&
(new RegExp(a,"i")).test(k(b))}},m=p("^BLOCKQUOTE|BODY|DETAILS|FIELDSET|FIGURE|TD$"),l=p("^ARTICLE|ASIDE|NAV|SECTION$"),i=p("^H[1-6]|HGROUP$"),w=function(a){return a&&a.tagName},j=function(a){var b=k(a);if(b=="HGROUP")for(b=1;b<=6;b++){if(a.getElementsByTagName("H"+b).length>0)return-b}else return-parseInt(b.substr(1))},n=function(a){return o(a.sections)},o=function(a){return a[a.length-1]};HTML5Outline=function(a){d=null;c=new h;g=[];t(a,u,v);return d!=null?d.outline:null}})();
;document.write(HTML5Outline(document.body).asHTML());