@xiee/utils
Advanced tools
Comparing version 1.1.2 to 1.1.3
@@ -0,5 +1,22 @@ | ||
// fix some issues in TOC generated by Hugo (Blackfriday or Goldmark) | ||
(function() { | ||
var toc = document.getElementById('TableOfContents'); | ||
const toc = document.getElementById('TableOfContents'); | ||
if (!toc) return; | ||
var li, ul = toc.querySelector('ul'); | ||
// fix header ids and a hrefs if a header contains a link | ||
toc.querySelectorAll('a[href^="#"]').forEach((a) => { | ||
let id = a.getAttribute('href').replace(/^#/, ''); | ||
const h = document.getElementById(id); | ||
// remove the URL from the id | ||
id = id.replace(/-https?-.+$/, ''); | ||
if (h) h.id = id; a.href = '#' + id; | ||
// if the TOC item has two <a>'s, remove the second if the first is empty | ||
if (a.innerHTML !== '') return; | ||
const a2 = a.nextElementSibling; | ||
if (!a2 || a2.tagName !== 'A') return; | ||
a.innerHTML = a2.innerHTML; | ||
a2.remove(); | ||
}); | ||
// Blackfriday may generate a TOC that has an empty bullet when all headings | ||
// are h2 and there is no h1: https://github.com/gohugoio/hugo/issues/1778#issuecomment-420036687 | ||
let li, ul = toc.querySelector('ul'); | ||
if (ul.childElementCount !== 1) return; | ||
@@ -6,0 +23,0 @@ li = ul.firstElementChild; |
{ | ||
"name": "@xiee/utils", | ||
"version": "1.1.2", | ||
"version": "1.1.3", | ||
"description": "Miscellaneous tools and utilities to manipulate HTML pages", | ||
@@ -5,0 +5,0 @@ "scripts": { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
12301
236