Show h2 headline in TOC only if id attr is set
There are two conditions to show a h2 headline in TOC: * the headline is visible * the id attribute is set Thereby the css style js-flag-hide-from-toc won't be used anymore.
This commit is contained in:
parent
6dbe7511c6
commit
6f1245bd15
@ -92,10 +92,6 @@
|
|||||||
background-color: #f2f2f2;
|
background-color: #f2f2f2;
|
||||||
}
|
}
|
||||||
|
|
||||||
.js-flag-hide-from-toc {
|
|
||||||
/* empty just used to hide h2 headings from TOCS */
|
|
||||||
}
|
|
||||||
|
|
||||||
.js-notify_box__msg--warning {
|
.js-notify_box__msg--warning {
|
||||||
color: #9F6000;
|
color: #9F6000;
|
||||||
background-color: #FEEFB3;
|
background-color: #FEEFB3;
|
||||||
@ -148,7 +144,7 @@ function goBack() {
|
|||||||
<h1>Analyse and visualise Linux OOM output</h1>
|
<h1>Analyse and visualise Linux OOM output</h1>
|
||||||
|
|
||||||
<nav class="table-of-contents" id="table_of_contents" role="navigation">
|
<nav class="table-of-contents" id="table_of_contents" role="navigation">
|
||||||
<h2 class="js-flag-hide-from-toc">On this page</h2>
|
<h2>On this page</h2>
|
||||||
<ul>
|
<ul>
|
||||||
</ul>
|
</ul>
|
||||||
</nav>
|
</nav>
|
||||||
|
@ -846,13 +846,19 @@ Killed process 6576 (java) total-vm:33914892kB, anon-rss:20629004kB, file-rss:0k
|
|||||||
show_element('notify_box')
|
show_element('notify_box')
|
||||||
|
|
||||||
def update_toc(self):
|
def update_toc(self):
|
||||||
"""Update the TOC to show current and visible headlines only"""
|
"""
|
||||||
|
Update the TOC to show current headlines only
|
||||||
|
|
||||||
|
There are two conditions to show a h2 headline in TOC:
|
||||||
|
* the headline is visible
|
||||||
|
* the id attribute is set
|
||||||
|
"""
|
||||||
new_toc = ''
|
new_toc = ''
|
||||||
|
|
||||||
toc_content = document.querySelectorAll('nav > ul')[0]
|
toc_content = document.querySelectorAll('nav > ul')[0]
|
||||||
|
|
||||||
for element in document.querySelectorAll('h2'):
|
for element in document.querySelectorAll('h2'):
|
||||||
if not is_visible(element) or element.classList.contains('js-flag-hide-from-toc'):
|
if not (is_visible(element) and element.id):
|
||||||
continue
|
continue
|
||||||
|
|
||||||
new_toc +='<li><a href="#{}">{}</a></li>'.format(element.id, element.textContent)
|
new_toc +='<li><a href="#{}">{}</a></li>'.format(element.id, element.textContent)
|
||||||
|
Loading…
Reference in New Issue
Block a user