/* Add a table of contents to an HTML document. Wikipedia automatically adds a per-page table of contents before the first non-top-level header on a page. This makes Wikipedia articles substantially easier to navigate, in my experience. I’ve been writing a bunch of documents in Markdown, and I wanted to add similar tables of contents to them. I could have added the feature to my Markdown processing pipeline (I already slap on a
Page Contents |
This table-of-contents code is free software. You can use it ' + 'on any properly-written web page you read. ' + 'Drag the following ' + 'bookmarklet ' + 'to your browser\'s bookmark bar, and click it when you want a ToC: ' + 'addtoc. ' + '
You can also use it in your own HTML documents. For instructions, ' + 'please see the source code of this copy at ' + ''+url+'. Share and enjoy!' + '
Properly-marked-up web pages include Wikipedia pages ' + "(although there's no point), " + 'WordPress blogs ' + "(even posts sometimes, although that's up to the author), " + "most documents written in Markdown (e.g. Raganwald's homoiconic), " + "Ars Technica articles, Henry Baker's papers, " + "the Lua reference manual, " + '' ); find('a', controls)[0].onclick = function() { inject_stylesheet(".addtoc_toc { display: none }"); return false; }; find('a', controls)[1].onclick = function() { controls.style.display = 'none'; link.style.display = 'inline'; return false; }; return rv; } function remove_all_inner_links_from(domnode) { var links = []; var links_search = find('a', domnode); for (var ii = 0; ii < links_search.length; ii++) { if (links_search[ii].href) links.push(links_search[ii]); } for (var ii = 0; ii < links.length; ii++) { while (links[ii].childNodes.length) { insert_before(remove(links[ii].firstChild), links[ii]); } remove(links[ii]); } } function remove_all_ids_from(domnodes) { for (var ii = 0; ii < domnodes.length; ii++) { var node = domnodes[ii]; if (node.id) node.id = undefined; if (node.childNodes) remove_all_ids_from(node.childNodes); } } function new_ol(rank, parent) { // If this is the top element on the stack, it might not have an //