Skip to content

Commit

Permalink
TOC: Numbers instead
Browse files Browse the repository at this point in the history
  • Loading branch information
Merlin Buczek committed Sep 14, 2019
1 parent aa6bfb6 commit 16f1bf7
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
5 changes: 3 additions & 2 deletions mpicms/static/css/custom.css
Original file line number Diff line number Diff line change
Expand Up @@ -556,14 +556,15 @@ body {
#toc {
font-size: 95%;
margin-top: 1rem;
line-height: 1.7rem;
}

#toc a::before {
/* #toc a::before {
content: '\2193';
padding-right: 0.5em;
font-size: 120%;
vertical-align: bottom;
}
} */

#toc .h2 {
text-indent: .25in;
Expand Down
13 changes: 12 additions & 1 deletion mpicms/static/js/toc.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
var toc = document.getElementById('toc');
if (toc) {
var headings = [].slice.call(document.getElementById('content').querySelectorAll('h1, h2, h3, h4, h5, h6'));
var tags = ['h1', 'h2', 'h3', 'h4', 'h5', 'h6'];
var indexes = Array(tags.length).fill(0);
headings.forEach(function (heading, index) {
var anchor = document.createElement('a');
anchor.setAttribute('name', 'toc' + index);
Expand All @@ -11,7 +13,16 @@ if (toc) {
link.textContent = heading.textContent;

var div = document.createElement('div');
div.setAttribute('class', heading.tagName.toLowerCase());
var tagName = heading.tagName.toLowerCase()
div.setAttribute('class', tagName);

// Number TOC
currentIndex = tags.indexOf(tagName)
indexes[currentIndex]++;
indexArray = indexes.slice(0, currentIndex +1)
indexes = indexArray.concat(Array(tags.length - currentIndex).fill(0))

link.textContent = `${indexArray.join('.')}. ${link.textContent}`;

div.appendChild(link);
toc.appendChild(div);
Expand Down

0 comments on commit 16f1bf7

Please sign in to comment.