function elementInToC(entry) {
    return document.querySelector(`#TableOfContents ul li a[href="#${entry.target.getAttribute('id')}"]`);
}

window.addEventListener('DOMContentLoaded', () => {
    var previousActive = null;

    const observer = new IntersectionObserver(entries => {
        var foundActive = false;
        entries.forEach(entry => {
            if (!foundActive && entry.isIntersecting) {
                if(previousActive) {
                    previousActive.classList.remove('active');
                }
                elementInToC(entry).classList.add('active');
                foundActive = true;
                previousActive = elementInToC(entry);
            }
            else {
                elementInToC(entry).classList.remove('active');
            }
        })

        if (!foundActive) {
            previousActive.classList.add('active');
        };
    });

    // Track all headers that have an `id` applied
    document.querySelectorAll('article h3[id], article h2[id]').forEach((section) => {
        observer.observe(section);
    });
});

// Post title doesn't get parsed as it is not part of the content file
(function addPostTitle2ToC() {
	var toc = document.getElementById('TableOfContents');
	if (!toc) return;
	var title = document.getElementById("post__title").innerText;
	var ul = toc.querySelector('ul');
	ul.outerHTML = `<ul><li><a href="#post__title" class="active">${title}</a>${ul.outerHTML}</li></ul>`;
})();

@@ -24,18 +24,16 @@
 ntry) %7B%0A
-  
   return
@@ -184,18 +184,16 @@
 () =%3E %7B%0A
-  
   var pr
@@ -214,18 +214,16 @@
  null;%0A%0A
-  
   const 
@@ -275,20 +275,16 @@
 %3E %7B%0A    
-   
- 
 var foun
@@ -300,20 +300,16 @@
  false;%0A
-    
     entr
@@ -337,22 +337,16 @@
 %7B%0A      
-    
-  
 if (!fou
@@ -377,32 +377,24 @@
 rsecting) %7B%0A
-        
         if(p
@@ -391,16 +391,17 @@
       if
+ 
 (previou
@@ -417,34 +417,24 @@
 %7B%0A          
-       
-   
 previousActi
@@ -476,33 +476,18 @@
     
-        %7D%0A       
+%7D%0A
         
  ele
@@ -474,33 +474,32 @@
       %7D%0A        
- 
 elementInToC(ent
@@ -523,32 +523,24 @@
 ('active');%0A
-        
         foun
@@ -555,24 +555,16 @@
 = true;%0A
-        
         
@@ -611,28 +611,16 @@
     
-      %7D%0A   
+%7D%0A
       
-   
 else
@@ -630,24 +630,16 @@
         
-      
-  
 elementI
@@ -688,32 +688,18 @@
     
-      %7D%0A  
+%7D%0A
     
-  
 %7D)%0A%0A
-    
     
@@ -720,30 +720,24 @@
 ve) %7B%0A      
-  
-    
 previousActi
@@ -760,28 +760,24 @@
 ('active');%0A
-    
     %7D;%0A    %7D
@@ -777,17 +777,13 @@
 ;%0A  
- 
- 
 %7D);%0A%0A
-  
   //
@@ -827,18 +827,16 @@
 applied%0A
-  
   docume
@@ -912,20 +912,16 @@
 n) =%3E %7B%0A
-    
     obse
@@ -943,18 +943,16 @@
 ction);%0A
-  
   %7D);%0A%7D)
@@ -1056,17 +1056,18 @@
 ToC() %7B%0A
-%09
+  
 var toc 
@@ -1112,17 +1112,18 @@
 ents');%0A
-%09
+  
 if (!toc
@@ -1132,17 +1132,18 @@
 return;%0A
-%09
+  
 var titl
@@ -1196,17 +1196,18 @@
 erText;%0A
-%09
+  
 var ul =
@@ -1236,9 +1236,10 @@
 ');%0A
-%09
+  
 ul.o

fix indentation