(v1.6.0.9011) unit tests
@ -0,0 +1,4 @@
|
||||
/* Styles for section anchors */
|
||||
a.anchor-section {margin-left: 10px; visibility: hidden; color: inherit;}
|
||||
a.anchor-section::before {content: '#';}
|
||||
.hasAnchor:hover a.anchor-section {visibility: visible;}
|
@ -0,0 +1,33 @@
|
||||
// Anchor sections v1.0 written by Atsushi Yasumoto on Oct 3rd, 2020.
|
||||
document.addEventListener('DOMContentLoaded', function() {
|
||||
// Do nothing if AnchorJS is used
|
||||
if (typeof window.anchors === 'object' && anchors.hasOwnProperty('hasAnchorJSLink')) {
|
||||
return;
|
||||
}
|
||||
|
||||
const h = document.querySelectorAll('h1, h2, h3, h4, h5, h6');
|
||||
|
||||
// Do nothing if sections are already anchored
|
||||
if (Array.from(h).some(x => x.classList.contains('hasAnchor'))) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// Use section id when pandoc runs with --section-divs
|
||||
const section_id = function(x) {
|
||||
return ((x.classList.contains('section') || (x.tagName === 'SECTION'))
|
||||
? x.id : '');
|
||||
};
|
||||
|
||||
// Add anchors
|
||||
h.forEach(function(x) {
|
||||
const id = x.id || section_id(x.parentElement);
|
||||
if (id === '') {
|
||||
return null;
|
||||
}
|
||||
let anchor = document.createElement('a');
|
||||
anchor.href = '#' + id;
|
||||
anchor.classList = ['anchor-section'];
|
||||
x.classList.add('hasAnchor');
|
||||
x.appendChild(anchor);
|
||||
});
|
||||
});
|
Before Width: | Height: | Size: 40 KiB After Width: | Height: | Size: 39 KiB |
Before Width: | Height: | Size: 51 KiB After Width: | Height: | Size: 51 KiB |
Before Width: | Height: | Size: 30 KiB After Width: | Height: | Size: 28 KiB |
Before Width: | Height: | Size: 34 KiB After Width: | Height: | Size: 36 KiB |
Before Width: | Height: | Size: 40 KiB After Width: | Height: | Size: 39 KiB |
Before Width: | Height: | Size: 51 KiB After Width: | Height: | Size: 50 KiB |
Before Width: | Height: | Size: 38 KiB After Width: | Height: | Size: 38 KiB |
Before Width: | Height: | Size: 26 KiB After Width: | Height: | Size: 26 KiB |
Before Width: | Height: | Size: 68 KiB After Width: | Height: | Size: 71 KiB |
Before Width: | Height: | Size: 45 KiB After Width: | Height: | Size: 46 KiB |