ドキュメントの概要から自動化されたTocを作成するjavascriptの場合は、あなたはすぐに開発する必要があります。この
研究を[私は実際にはコピー&ペーストの解決策を見つけていない]:
この
[ADDON]
は、ユーザー@unorからの推奨読書:github.com/DylanFM/outlinerは別のjavascriptがあり、このjsFiddleに送ってくれました起動。
Javascriptを
// See http://html5doctor.com/document-outlines/
// That article begins with info on HTML4 document outlines
// This doesn't do that yet, it just handles the HTML5 stuff beneath in the article
// I'm sure there are problems with handling that HTML5 stuff tho
var headingElements = ['H1', 'H2', 'H3', 'H4', 'H5', 'H6'],
sectioningElements = ['SECTION', 'ARTICLE', 'NAV', 'ASIDE'];
function makeOutline(root) {
var ar = [],
el = root.firstChild,
nested, hg;
while(el) {
// If it's a sectioning element, create a new level in the outline
if(sectioningElements.indexOf(el.tagName) > -1) {
nested = makeOutline(el);
if(nested.every(function(i){ return typeof i !== 'string'; })) {
nested.unshift('Untitled ' + el.tagName.toLowerCase());
}
ar.push(nested);
} else if(headingElements.indexOf(el.tagName) > -1) {
ar.push(el.textContent);
} else if(el.tagName === 'HGROUP') {
hg = undefined;
// Find the highest heading element within
// Use its text, otherwhise it's untitled
try {
headingElements.forEach(function(t) {
els = el.getElementsByTagName(t);
if(els.length) {
hg = els[0].textContent;
throw BreakException;
}
});
} catch(e) {}
if(!hg) {
hg = 'Untitled hgroup';
}
ar.push(hg);
}
el = el.nextSibling;
}
return ar;
};
var outline = makeOutline(document.body);
// This is just used for displaying the outline.
// Inspect the outline variable to see the generated array:
// console.log(outline);
function describeOutline(outline) {
var indentForDepth = function(depth) {
var str = '';
for(i=depth;i>0;i--) {
str += '\t';
}
return str;
},
childrenAreStrings = function(ar, depth) {
var depth = (depth && (depth + 1)) || 1;
return ar.map(function(item) {
if({}.toString.call(item)=='[object Array]') {
return childrenAreStrings(item, depth).join('\n');
} else {
return indentForDepth(depth) + '- ' + String(item);
}
});
};
// Make sure all items in ar are strings
return childrenAreStrings(outline).join('\n');
}
(document.getElementsByTagName('pre')[0]).textContent = describeOutline(outline);
たぶん私はあなたの質問を理解していない..あなたが助けを求める前に、多くの努力をしなかった迅速なGoogle検索のショー:https://www.google.ca/search?num = 100&hl = fr&newwindow = 1&site =&source = hp&q =生成+ドキュメント+ナビゲーション+ + HTML5 +アウトライン+アルゴリズム+および+ CSS –
...最初の結果が表示されます:http://coding.smashingmagazine.com/2011/08/16/html5-and-the-document-outlining-algorithm/ –
TeXの/ tableofcontentsのように明示的に書かなくても、どのようにして目次を文書に表示することができますか? way(javascriptなし)では、ブラウザは最終的に方法を提供しますか?私はその記事を読んで、私はそれがこれに対処するとは思わない。 – ohmygoodness