1// Anchor sections v1.0 written by Atsushi Yasumoto on Oct 3rd, 2020. 2document.addEventListener('DOMContentLoaded', function() { 3 // Do nothing if AnchorJS is used 4 if (typeof window.anchors === 'object' && anchors.hasOwnProperty('hasAnchorJSLink')) { 5 return; 6 } 7 8 const h = document.querySelectorAll('h1, h2, h3, h4, h5, h6'); 9 10 // Do nothing if sections are already anchored 11 if (Array.from(h).some(x => x.classList.contains('hasAnchor'))) { 12 return null; 13 } 14 15 // Use section id when pandoc runs with --section-divs 16 const section_id = function(x) { 17 return ((x.classList.contains('section') || (x.tagName === 'SECTION')) 18 ? x.id : ''); 19 }; 20 21 // Add anchors 22 h.forEach(function(x) { 23 const id = x.id || section_id(x.parentElement); 24 if (id === '' || x.matches(':empty')) { 25 return null; 26 } 27 let anchor = document.createElement('a'); 28 anchor.href = '#' + id; 29 anchor.classList = ['anchor-section']; 30 x.classList.add('hasAnchor'); 31 x.appendChild(anchor); 32 }); 33});
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.