From 3ae5d4c1e311067ef75541bb4aa036fc47ce1c99 Mon Sep 17 00:00:00 2001 From: David Bolack Date: Wed, 22 May 2024 16:30:12 -0500 Subject: [PATCH] Slight reworking of style naming for Table of Contents Also uses :is operator for cleaner? looking CSS Lastly, removes {{partCover}} from automatic exclusion. --- themes/V3/5ePHB/snippets.js | 8 ++--- .../V3/5ePHB/snippets/tableOfContents.gen.js | 9 ++++-- themes/V3/5ePHB/style.less | 30 ++++++++----------- 3 files changed, 23 insertions(+), 24 deletions(-) diff --git a/themes/V3/5ePHB/snippets.js b/themes/V3/5ePHB/snippets.js index 5c93c800..2c18354b 100644 --- a/themes/V3/5ePHB/snippets.js +++ b/themes/V3/5ePHB/snippets.js @@ -33,26 +33,26 @@ module.exports = [ { name : 'Include in ToC up to H3', icon : 'fas fa-dice-six', - gen : dedent `\n{{addToC + gen : dedent `\n{{tocH3 }}\n`, }, { name : 'Include in ToC up to H4', icon : 'fas fa-dice-four', - gen : dedent `\n{{addToC,tocH4 + gen : dedent `\n{{tocH4 }}\n`, }, { name : 'Include in ToC up to H5', icon : 'fas fa-dice-five', - gen : dedent `\n{{addToC,tocH5 + gen : dedent `\n{{tocH5 }}\n`, }, { name : 'Include in ToC up to H6', icon : 'fas fa-dice-six', - gen : dedent `\n{{addToC,tocH6 + gen : dedent `\n{{tocH6 }}\n`, } ] diff --git a/themes/V3/5ePHB/snippets/tableOfContents.gen.js b/themes/V3/5ePHB/snippets/tableOfContents.gen.js index 6bb87cbf..9e8ed804 100644 --- a/themes/V3/5ePHB/snippets/tableOfContents.gen.js +++ b/themes/V3/5ePHB/snippets/tableOfContents.gen.js @@ -27,7 +27,7 @@ const getTOC = (pages)=>{ const iframeDocument = iframe.contentDocument || iframe.contentWindow.document; const headings = iframeDocument.querySelectorAll('h1, h2, h3, h4, h5, h6'); const headerDepth = ['H1', 'H2', 'H3', 'H4', 'H5', 'H6']; - const exclusionElements = iframeDocument.querySelectorAll('frontCover insideCover partCover backCover'); + const exclusionElements = iframeDocument.querySelectorAll('frontCover insideCover backCover'); const excludedPages = []; // Build a list of excluded pages. @@ -40,7 +40,12 @@ const getTOC = (pages)=>{ const onPage = parseInt(heading.closest('.page,.phb').id?.replace(/^p/, '')); const ToCExclude = getComputedStyle(heading).getPropertyValue('--TOC'); - if((ToCExclude != 'exclude') && (!excludedPages.includes(onPage))) { + if(heading.tagName == 'H1') { + console.log(heading); + console.log(ToCExclude); + } + + if(((ToCExclude != 'exclude') && (!excludedPages.includes(onPage)))) { recursiveAdd(heading.innerText.trim(), onPage, headerDepth.indexOf(heading.tagName), res); } }); diff --git a/themes/V3/5ePHB/style.less b/themes/V3/5ePHB/style.less index 0ba6062e..68ea5eda 100644 --- a/themes/V3/5ePHB/style.less +++ b/themes/V3/5ePHB/style.less @@ -794,29 +794,23 @@ h6, .page:has(.frontCover), .page:has(.backCover), .page:has(.insideCover), -.page:has(.partCover), .monster, .noToC, .toc { --TOC: exclude; } -.tocH4 { - h4 { --TOC: include; } -} -.tocH5 { - h4 { --TOC: include; } - h5 { --TOC: include; } -} -.tocH6 { - h4 { --TOC: include; } - h5 { --TOC: include; } - h6 { --TOC: include; } -} +.tocH1 :is(h1) { --TOC: include; } +.tocH2 :is(h1, h2) {--TOC: include; } +.tocH3 :is(h1, h2, h3) {--TOC: include; } +.tocH4 :is(h1, h2, h3, h4) {--TOC: include; } +.tocH5 :is(h1, h2, h3, h4, h5) {--TOC: include; } +.tocH6 :is(h1, h2, h3, h4, h5, h6) {--TOC: include; } -.addToC { - h1 {--TOC: include; } - h2 {--TOC: include; } - h3 {--TOC: include; } -} +.tocIncludeH1 h1 {--TOC: include; } +.tocIncludeH2 h2 {--TOC: include; } +.tocIncludeH3 h3 {--TOC: include; } +.tocIncludeH4 h4 {--TOC: include; } +.tocIncludeH5 h5 {--TOC: include; } +.tocIncludeH6 h6 {--TOC: include; } .page { &:has(.toc)::after { display : none; }