From 854c21639a1b30085613ed31439042554d0bdf82 Mon Sep 17 00:00:00 2001 From: David Bolack Date: Sat, 20 Jan 2024 11:58:17 -0600 Subject: [PATCH 01/28] CSS based ToC exclusion system either I am building the lookup incorrectly or Chrome is not letting me see variables via computedStyles. --- .../V3/5ePHB/snippets/tableOfContents.gen.js | 47 ++++++++++++------- themes/V3/5ePHB/style.less | 3 ++ 2 files changed, 33 insertions(+), 17 deletions(-) diff --git a/themes/V3/5ePHB/snippets/tableOfContents.gen.js b/themes/V3/5ePHB/snippets/tableOfContents.gen.js index 97d82ed40..1be583ba1 100644 --- a/themes/V3/5ePHB/snippets/tableOfContents.gen.js +++ b/themes/V3/5ePHB/snippets/tableOfContents.gen.js @@ -1,7 +1,7 @@ const _ = require('lodash'); const dedent = require('dedent-tabs').default; -const getTOC = (pages)=>{ +const getTOC = ()=>{ const add1 = (title, page)=>{ res.push({ title : title, @@ -27,32 +27,45 @@ const getTOC = (pages)=>{ }); }; + const getParentPageNumber = (e)=>{ + let tE = e; + while (tE?.tagName != 'BODY') { + if((tE.className == 'page') || (tE.className.split(' ')?.includes('Page'))) { + // Test for excluded pages here. + return parseInt(tE.id.replace(/^p/, '')); + } + tE = tE.parentElement; + } + return -1; + }; + const res = []; - _.each(pages, (page, pageNum)=>{ - if(!page.includes("{{frontCover}}") && !page.includes("{{insideCover}}") && !page.includes("{{partCover}}") && !page.includes("{{backCover}}")) { - const lines = page.split('\n'); - _.each(lines, (line)=>{ - if(_.startsWith(line, '# ')){ - const title = line.replace('# ', ''); - add1(title, pageNum); + const iframe = document.getElementById('BrewRenderer'); + const iframeDocument = iframe.contentDocument || iframe.contentWindow.document; + const headings = iframeDocument.querySelectorAll('h1, h2, h3'); + + _.each(headings, (heading)=>{ + const onPage = getParentPageNumber(heading); + if(getComputedStyle(heading).getPropertyValue('--TOC') != 'exclude') { + if(onPage != -1) { + const headingText = heading.innerText; + if(heading.tagName == 'H1') { + add1(headingText, onPage); } - if(_.startsWith(line, '## ')){ - const title = line.replace('## ', ''); - add2(title, pageNum); + if(heading.tagName == 'H2') { + add2(headingText, onPage); } - if(_.startsWith(line, '### ')){ - const title = line.replace('### ', ''); - add3(title, pageNum); + if(heading.tagName == 'H3') { + add3(headingText, onPage); } - }); + } } }); return res; }; module.exports = function(props){ - const pages = props.brew.text.split('\\page'); - const TOC = getTOC(pages); + const TOC = getTOC(); const markdown = _.reduce(TOC, (r, g1, idx1)=>{ if(g1.title !== null) { r.push(`- ### [{{ ${g1.title}}}{{ ${g1.page}}}](#p${g1.page})`); diff --git a/themes/V3/5ePHB/style.less b/themes/V3/5ePHB/style.less index 6c6634ce7..fba45df42 100644 --- a/themes/V3/5ePHB/style.less +++ b/themes/V3/5ePHB/style.less @@ -314,6 +314,7 @@ border-image : @monsterBorderImage 14 round; border-image-outset : 0px 2px; box-shadow : 1px 4px 14px #888888; + --TOC : "exclude"; } position : relative; @@ -329,11 +330,13 @@ margin-bottom : 0; font-size : 0.304cm; //Monster size and type subtext } + --TOC : "exclude"; } h3 { font-family : 'ScalySansSmallCapsRemake'; font-size : 0.45cm; border-bottom : 1.5px solid var(--HB_Color_HeaderText); + --TOC : "exclude"; } //Triangle dividers From 622827efda8de694d1fd428ef5cdcb073b717133 Mon Sep 17 00:00:00 2001 From: David Bolack Date: Sat, 20 Jan 2024 20:47:27 -0600 Subject: [PATCH 02/28] Fix Exclusion examination --- themes/V3/5ePHB/snippets/tableOfContents.gen.js | 17 +++-------------- themes/V3/5ePHB/style.less | 10 ++++++++++ 2 files changed, 13 insertions(+), 14 deletions(-) diff --git a/themes/V3/5ePHB/snippets/tableOfContents.gen.js b/themes/V3/5ePHB/snippets/tableOfContents.gen.js index 1be583ba1..c6ac0671d 100644 --- a/themes/V3/5ePHB/snippets/tableOfContents.gen.js +++ b/themes/V3/5ePHB/snippets/tableOfContents.gen.js @@ -27,26 +27,15 @@ const getTOC = ()=>{ }); }; - const getParentPageNumber = (e)=>{ - let tE = e; - while (tE?.tagName != 'BODY') { - if((tE.className == 'page') || (tE.className.split(' ')?.includes('Page'))) { - // Test for excluded pages here. - return parseInt(tE.id.replace(/^p/, '')); - } - tE = tE.parentElement; - } - return -1; - }; - const res = []; const iframe = document.getElementById('BrewRenderer'); const iframeDocument = iframe.contentDocument || iframe.contentWindow.document; const headings = iframeDocument.querySelectorAll('h1, h2, h3'); _.each(headings, (heading)=>{ - const onPage = getParentPageNumber(heading); - if(getComputedStyle(heading).getPropertyValue('--TOC') != 'exclude') { + const onPage = parseInt(heading.closest('.page,.phb').id.replace(/^p/, '')); + const ToCExclude = getComputedStyle(heading).getPropertyValue('--TOC'); + if(ToCExclude != '"exclude"') { if(onPage != -1) { const headingText = heading.innerText; if(heading.tagName == 'H1') { diff --git a/themes/V3/5ePHB/style.less b/themes/V3/5ePHB/style.less index fba45df42..03dc021c7 100644 --- a/themes/V3/5ePHB/style.less +++ b/themes/V3/5ePHB/style.less @@ -799,6 +799,16 @@ // ***************************** // * TABLE OF CONTENTS // *****************************/ + +.page:has(.frontCover), +.page:has(.backCover), +.page:has(.insideCover), +.page:has(.partCover), +.monster h3, +.monster h4, +h5, h6, +.toc { --TOC: exclude; } + .page { &:has(.toc)::after { display : none; } .toc { From 26c4b1afa6ccd4c061a7fdd4c2698a0f7742b0e8 Mon Sep 17 00:00:00 2001 From: David Bolack Date: Sun, 21 Jan 2024 08:58:14 -0600 Subject: [PATCH 03/28] Add toggle-on classes. --- themes/V3/5ePHB/style.less | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/themes/V3/5ePHB/style.less b/themes/V3/5ePHB/style.less index 03dc021c7..5c7771350 100644 --- a/themes/V3/5ePHB/style.less +++ b/themes/V3/5ePHB/style.less @@ -314,7 +314,6 @@ border-image : @monsterBorderImage 14 round; border-image-outset : 0px 2px; box-shadow : 1px 4px 14px #888888; - --TOC : "exclude"; } position : relative; @@ -330,13 +329,11 @@ margin-bottom : 0; font-size : 0.304cm; //Monster size and type subtext } - --TOC : "exclude"; } h3 { font-family : 'ScalySansSmallCapsRemake'; font-size : 0.45cm; border-bottom : 1.5px solid var(--HB_Color_HeaderText); - --TOC : "exclude"; } //Triangle dividers @@ -800,15 +797,22 @@ // * TABLE OF CONTENTS // *****************************/ +// Default Exclusions .page:has(.frontCover), .page:has(.backCover), .page:has(.insideCover), .page:has(.partCover), -.monster h3, -.monster h4, -h5, h6, +.monster, +.noToC, .toc { --TOC: exclude; } +// Manual Inclusion classes + +.addToC, +.addh1, .addh2, .addh3, .addh4, .addh5, .addh6, .addh1h2 h1, .addh1h2 h2, +.addh1h3 h1, .addh1h3 h2, .addh1h3 h3, .addh1h4 h1, .addh1h4 h2, .addh1h4 h3, .addh1h4 h4, +.addh1h5 h1, .addh1h5 h2, .addh1h5 h3, .addh1h5 h4, .addh1h5 h5 { --TOC: include; } + .page { &:has(.toc)::after { display : none; } .toc { From b8ee696b69cd676c3adb4982c773e8f543fa5358 Mon Sep 17 00:00:00 2001 From: David Bolack Date: Wed, 24 Jan 2024 15:42:22 -0600 Subject: [PATCH 04/28] Add manual exclusion classes for ToC exclusion. --- themes/V3/5ePHB/style.less | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/themes/V3/5ePHB/style.less b/themes/V3/5ePHB/style.less index 5c7771350..a06817566 100644 --- a/themes/V3/5ePHB/style.less +++ b/themes/V3/5ePHB/style.less @@ -813,6 +813,11 @@ .addh1h3 h1, .addh1h3 h2, .addh1h3 h3, .addh1h4 h1, .addh1h4 h2, .addh1h4 h3, .addh1h4 h4, .addh1h5 h1, .addh1h5 h2, .addh1h5 h3, .addh1h5 h4, .addh1h5 h5 { --TOC: include; } +// Manual Exclusion classes +.noh1, .noh2, .noh3, .noh4, .noh5, .noh6, .noh1h2 h1, .noh1h2 h2, +.noh1h3 h1, .noh1h3 h2, .noh1h3 h3, .noh1h4 h1, .noh1h4 h2, .noh1h4 h3, .noh1h4 h4, +.noh1h5 h1, .noh1h5 h2, .noh1h5 h3, .noh1h5 h4, .noh1h5 h5 { --TOC: exclude; } + .page { &:has(.toc)::after { display : none; } .toc { From 85caf0a892644e6bf85129b1a763323334025f4f Mon Sep 17 00:00:00 2001 From: David Bolack Date: Mon, 29 Jan 2024 20:14:52 -0600 Subject: [PATCH 05/28] Add fixes to account for no page numbers Clear out manual toggles. --- themes/V3/5ePHB/snippets/tableOfContents.gen.js | 4 ++-- themes/V3/5ePHB/style.less | 12 ------------ 2 files changed, 2 insertions(+), 14 deletions(-) diff --git a/themes/V3/5ePHB/snippets/tableOfContents.gen.js b/themes/V3/5ePHB/snippets/tableOfContents.gen.js index c6ac0671d..150b67c30 100644 --- a/themes/V3/5ePHB/snippets/tableOfContents.gen.js +++ b/themes/V3/5ePHB/snippets/tableOfContents.gen.js @@ -33,10 +33,10 @@ const getTOC = ()=>{ const headings = iframeDocument.querySelectorAll('h1, h2, h3'); _.each(headings, (heading)=>{ - const onPage = parseInt(heading.closest('.page,.phb').id.replace(/^p/, '')); + const onPage = parseInt(heading.closest('.page,.phb').id?.replace(/^p/, '')); const ToCExclude = getComputedStyle(heading).getPropertyValue('--TOC'); if(ToCExclude != '"exclude"') { - if(onPage != -1) { + if(!isNaN(onPage)) { const headingText = heading.innerText; if(heading.tagName == 'H1') { add1(headingText, onPage); diff --git a/themes/V3/5ePHB/style.less b/themes/V3/5ePHB/style.less index a06817566..1047ed729 100644 --- a/themes/V3/5ePHB/style.less +++ b/themes/V3/5ePHB/style.less @@ -806,18 +806,6 @@ .noToC, .toc { --TOC: exclude; } -// Manual Inclusion classes - -.addToC, -.addh1, .addh2, .addh3, .addh4, .addh5, .addh6, .addh1h2 h1, .addh1h2 h2, -.addh1h3 h1, .addh1h3 h2, .addh1h3 h3, .addh1h4 h1, .addh1h4 h2, .addh1h4 h3, .addh1h4 h4, -.addh1h5 h1, .addh1h5 h2, .addh1h5 h3, .addh1h5 h4, .addh1h5 h5 { --TOC: include; } - -// Manual Exclusion classes -.noh1, .noh2, .noh3, .noh4, .noh5, .noh6, .noh1h2 h1, .noh1h2 h2, -.noh1h3 h1, .noh1h3 h2, .noh1h3 h3, .noh1h4 h1, .noh1h4 h2, .noh1h4 h3, .noh1h4 h4, -.noh1h5 h1, .noh1h5 h2, .noh1h5 h3, .noh1h5 h4, .noh1h5 h5 { --TOC: exclude; } - .page { &:has(.toc)::after { display : none; } .toc { From 1705e66be2ac52cef7b6ba2349f1725522427cf9 Mon Sep 17 00:00:00 2001 From: dbolack Date: Sat, 23 Mar 2024 18:57:53 -0500 Subject: [PATCH 06/28] Corrections per PR Remove off by one error realted to change in page number detection. Dewrap quotes from exclude screen. --- themes/V3/5ePHB/snippets/tableOfContents.gen.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/themes/V3/5ePHB/snippets/tableOfContents.gen.js b/themes/V3/5ePHB/snippets/tableOfContents.gen.js index c12205c69..d43ff3854 100644 --- a/themes/V3/5ePHB/snippets/tableOfContents.gen.js +++ b/themes/V3/5ePHB/snippets/tableOfContents.gen.js @@ -5,7 +5,7 @@ const getTOC = ()=>{ const add1 = (title, page)=>{ res.push({ title : title, - page : page + 1, + page : page, children : [] }); }; @@ -13,7 +13,7 @@ const getTOC = ()=>{ if(!_.last(res)) add1(null, page); _.last(res).children.push({ title : title, - page : page + 1, + page : page, children : [] }); }; @@ -22,7 +22,7 @@ const getTOC = ()=>{ if(!_.last(_.last(res).children)) add2(null, page); _.last(_.last(res).children).children.push({ title : title, - page : page + 1, + page : page, children : [] }); }; @@ -35,7 +35,7 @@ const getTOC = ()=>{ _.each(headings, (heading)=>{ const onPage = parseInt(heading.closest('.page,.phb').id?.replace(/^p/, '')); const ToCExclude = getComputedStyle(heading).getPropertyValue('--TOC'); - if(ToCExclude != '"exclude"') { + if(ToCExclude != 'exclude') { if(!isNaN(onPage)) { const headingText = heading.innerText; if(heading.tagName == 'H1') { From 7ca10ff5a48510fe6593fb77fa9fa5ed20232394 Mon Sep 17 00:00:00 2001 From: David Bolack Date: Mon, 25 Mar 2024 16:13:07 -0500 Subject: [PATCH 07/28] Add requested additions to code Add snippet additions to handle Add h4, Add h4-h5, add h4-h6 Add collection of headers h4-h6 and rendering of h4 to h6. --- themes/V3/5ePHB/snippets.js | 31 ++++++- .../V3/5ePHB/snippets/tableOfContents.gen.js | 81 +++++++++++++++++-- themes/V3/5ePHB/style.less | 16 ++++ 3 files changed, 120 insertions(+), 8 deletions(-) diff --git a/themes/V3/5ePHB/snippets.js b/themes/V3/5ePHB/snippets.js index c0933d70d..c8b3dbde1 100644 --- a/themes/V3/5ePHB/snippets.js +++ b/themes/V3/5ePHB/snippets.js @@ -21,9 +21,34 @@ module.exports = [ view : 'text', snippets : [ { - name : 'Table of Contents', - icon : 'fas fa-book', - gen : TableOfContentsGen + name : 'Table of Contents', + icon : 'fas fa-book', + gen : TableOfContentsGen, + subsnippets : [ + { + name : 'Table of Contents', + icon : 'fas fa-book', + gen : TableOfContentsGen, + }, + { + name : 'Include H4', + icon : 'fas fa-dice-four', + gen : dedent `{{tocH4 + }}`, + }, + { + name : 'Include H4, H5', + icon : 'fas fa-dice-five', + gen : dedent `{{tocH5 + }}`, + }, + { + name : 'Include H4-H6', + icon : 'fas fa-dice-six', + gen : dedent `{{tocH6 + }}`, + }, + ] }, { name : 'Index', diff --git a/themes/V3/5ePHB/snippets/tableOfContents.gen.js b/themes/V3/5ePHB/snippets/tableOfContents.gen.js index d43ff3854..2d3865bbf 100644 --- a/themes/V3/5ePHB/snippets/tableOfContents.gen.js +++ b/themes/V3/5ePHB/snippets/tableOfContents.gen.js @@ -26,11 +26,44 @@ const getTOC = ()=>{ children : [] }); }; + const add4 = (title, page)=>{ + if(!_.last(res)) add1(null, page); + if(!_.last(_.last(res).children)) add2(null, page); + if(!_.last(!_.last(_.last(res).children))) add3(null, page); + _.last(_.last(_.last(res).children).children).children.push({ + title : title, + page : page, + children : [] + }); + }; + const add5 = (title, page)=>{ + if(!_.last(res)) add1(null, page); + if(!_.last(_.last(res).children)) add2(null, page); + if(!_.last(!_.last(_.last(res).children))) add3(null, page); + if(!_.last(!_.last(!_.last(_.last(res).children)))) add4(null, page); + _.last(_.last(_.last(_.last(res).children).children).children).children.push({ + title : title, + page : page, + children : [] + }); + }; + const add6 = (title, page)=>{ + if(!_.last(res)) add1(null, page); + if(!_.last(_.last(res).children)) add2(null, page); + if(!_.last(!_.last(_.last(res).children))) add3(null, page); + if(!_.last(!_.last(!_.last(_.last(res).children)))) add4(null, page); + if(!_.last(!_.last(!_.last(!_.last(_.last(res).children))))) add5(null, page); + _.last(_.last(_.last(_.last(_.last(res).children).children).children).children).children.push({ + title : title, + page : page, + children : [] + }); + }; const res = []; const iframe = document.getElementById('BrewRenderer'); const iframeDocument = iframe.contentDocument || iframe.contentWindow.document; - const headings = iframeDocument.querySelectorAll('h1, h2, h3'); + const headings = iframeDocument.querySelectorAll('h1, h2, h3, h4, h5, h6'); _.each(headings, (heading)=>{ const onPage = parseInt(heading.closest('.page,.phb').id?.replace(/^p/, '')); @@ -47,6 +80,15 @@ const getTOC = ()=>{ if(heading.tagName == 'H3') { add3(headingText, onPage); } + if(heading.tagName == 'H4') { + add4(headingText, onPage); + } + if(heading.tagName == 'H5') { + add5(headingText, onPage); + } + if(heading.tagName == 'H6') { + add6(headingText, onPage); + } } } }); @@ -66,11 +108,40 @@ module.exports = function(props){ } if(g2.children.length){ _.each(g2.children, (g3, idx3)=>{ - if(g2.title !== null) { - r.push(` - [{{ ${g3.title}}}{{ ${g3.page}}}](#p${g3.page})`); - } else { // Don't over-indent if no level-2 parent entry - r.push(` - [{{ ${g3.title}}}{{ ${g3.page}}}](#p${g3.page})`); + if(g3.title !== null) { + if(g2.title !== null) { + r.push(` - [{{ ${g3.title}}}{{ ${g3.page}}}](#p${g3.page})`); + } else { // Don't over-indent if no level-2 parent entry + r.push(` - [{{ ${g3.title}}}{{ ${g3.page}}}](#p${g3.page})`); + } } + _.each(g3.children, (g4, idx4)=>{ + if(g4.title !== null) { + if(g3.title !== null) { + r.push(` - [{{ ${g4.title}}}{{ ${g4.page}}}](#p${g4.page})`); + } else { // Don't over-indent if no level-3 parent entry + r.push(` - [{{ ${g4.title}}}{{ ${g4.page}}}](#p${g4.page})`); + } + } + _.each(g4.children, (g5, idx5)=>{ + if(g5.title !== null) { + if(g4.title !== null) { + r.push(` - [{{ ${g5.title}}}{{ ${g5.page}}}](#p${g5.page})`); + } else { // Don't over-indent if no level-4 parent entry + r.push(` - [{{ ${g5.title}}}{{ ${g5.page}}}](#p${g5.page})`); + } + } + _.each(g5.children, (g6, idx6)=>{ + if(g6.title !== null) { + if(g5.title !== null) { + r.push(` - [{{ ${g6.title}}}{{ ${g6.page}}}](#p${g6.page})`); + } else { // Don't over-indent if no level-5 parent entry + r.push(` - [{{ ${g6.title}}}{{ ${g6.page}}}](#p${g6.page})`); + } + } + }); + }); + }); }); } }); diff --git a/themes/V3/5ePHB/style.less b/themes/V3/5ePHB/style.less index ceb811a23..4473ab7f8 100644 --- a/themes/V3/5ePHB/style.less +++ b/themes/V3/5ePHB/style.less @@ -791,6 +791,9 @@ // *****************************/ // Default Exclusions +h4, +h5, +h6, .page:has(.frontCover), .page:has(.backCover), .page:has(.insideCover), @@ -799,6 +802,19 @@ .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; } +} + .page { &:has(.toc)::after { display : none; } .toc { From 40d0e7e90ed215449d604afb98774fa864cd9748 Mon Sep 17 00:00:00 2001 From: David Bolack Date: Mon, 25 Mar 2024 16:32:03 -0500 Subject: [PATCH 08/28] Trim space off of ToC entries. --- themes/V3/5ePHB/snippets/tableOfContents.gen.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/themes/V3/5ePHB/snippets/tableOfContents.gen.js b/themes/V3/5ePHB/snippets/tableOfContents.gen.js index 2d3865bbf..cd8ac1e4e 100644 --- a/themes/V3/5ePHB/snippets/tableOfContents.gen.js +++ b/themes/V3/5ePHB/snippets/tableOfContents.gen.js @@ -70,7 +70,7 @@ const getTOC = ()=>{ const ToCExclude = getComputedStyle(heading).getPropertyValue('--TOC'); if(ToCExclude != 'exclude') { if(!isNaN(onPage)) { - const headingText = heading.innerText; + const headingText = heading.innerText.trim(); if(heading.tagName == 'H1') { add1(headingText, onPage); } From 9d3f7fe55673b0692b2225ca9e7f6f9d93f660b4 Mon Sep 17 00:00:00 2001 From: David Bolack Date: Mon, 25 Mar 2024 18:58:29 -0500 Subject: [PATCH 09/28] Fix H3-H6 entries in ToC generation --- themes/V3/5ePHB/snippets/tableOfContents.gen.js | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/themes/V3/5ePHB/snippets/tableOfContents.gen.js b/themes/V3/5ePHB/snippets/tableOfContents.gen.js index cd8ac1e4e..7c5cae7d3 100644 --- a/themes/V3/5ePHB/snippets/tableOfContents.gen.js +++ b/themes/V3/5ePHB/snippets/tableOfContents.gen.js @@ -110,33 +110,33 @@ module.exports = function(props){ _.each(g2.children, (g3, idx3)=>{ if(g3.title !== null) { if(g2.title !== null) { - r.push(` - [{{ ${g3.title}}}{{ ${g3.page}}}](#p${g3.page})`); + r.push(` - #### [{{ ${g3.title}}}{{ ${g3.page}}}](#p${g3.page})`); } else { // Don't over-indent if no level-2 parent entry - r.push(` - [{{ ${g3.title}}}{{ ${g3.page}}}](#p${g3.page})`); + r.push(` - #### [{{ ${g3.title}}}{{ ${g3.page}}}](#p${g3.page})`); } } _.each(g3.children, (g4, idx4)=>{ if(g4.title !== null) { if(g3.title !== null) { - r.push(` - [{{ ${g4.title}}}{{ ${g4.page}}}](#p${g4.page})`); + r.push(` - #### [{{ ${g4.title}}}{{ ${g4.page}}}](#p${g4.page})`); } else { // Don't over-indent if no level-3 parent entry - r.push(` - [{{ ${g4.title}}}{{ ${g4.page}}}](#p${g4.page})`); + r.push(` - #### [{{ ${g4.title}}}{{ ${g4.page}}}](#p${g4.page})`); } } _.each(g4.children, (g5, idx5)=>{ if(g5.title !== null) { if(g4.title !== null) { - r.push(` - [{{ ${g5.title}}}{{ ${g5.page}}}](#p${g5.page})`); + r.push(` - #### [{{ ${g5.title}}}{{ ${g5.page}}}](#p${g5.page})`); } else { // Don't over-indent if no level-4 parent entry - r.push(` - [{{ ${g5.title}}}{{ ${g5.page}}}](#p${g5.page})`); + r.push(` - #### [{{ ${g5.title}}}{{ ${g5.page}}}](#p${g5.page})`); } } _.each(g5.children, (g6, idx6)=>{ if(g6.title !== null) { if(g5.title !== null) { - r.push(` - [{{ ${g6.title}}}{{ ${g6.page}}}](#p${g6.page})`); + r.push(` - #### [{{ ${g6.title}}}{{ ${g6.page}}}](#p${g6.page})`); } else { // Don't over-indent if no level-5 parent entry - r.push(` - [{{ ${g6.title}}}{{ ${g6.page}}}](#p${g6.page})`); + r.push(` - #### [{{ ${g6.title}}}{{ ${g6.page}}}](#p${g6.page})`); } } }); From 211fe48e290cf649530936ad6d54a6ac4ec57cd1 Mon Sep 17 00:00:00 2001 From: David Bolack Date: Mon, 25 Mar 2024 19:06:38 -0500 Subject: [PATCH 10/28] Attempt to block H4-h6 from existing ToCs from showing up in a new ToC. --- themes/V3/5ePHB/style.less | 3 +++ 1 file changed, 3 insertions(+) diff --git a/themes/V3/5ePHB/style.less b/themes/V3/5ePHB/style.less index 4473ab7f8..9898bff0b 100644 --- a/themes/V3/5ePHB/style.less +++ b/themes/V3/5ePHB/style.less @@ -831,6 +831,9 @@ h6, text-decoration : none; &:hover { text-decoration : underline; } } + h1, h2, h3, h4, h5, h6 { + --TOC: exclude !important; + } h4 { margin-top : 0.2cm; line-height : 0.4cm; From 733b9299404888a6cb317ce5726f05e8dd3cf158 Mon Sep 17 00:00:00 2001 From: David Bolack Date: Mon, 25 Mar 2024 19:36:30 -0500 Subject: [PATCH 11/28] Integrate code recursion from 3254. --- .../V3/5ePHB/snippets/tableOfContents.gen.js | 66 +++++-------------- 1 file changed, 18 insertions(+), 48 deletions(-) diff --git a/themes/V3/5ePHB/snippets/tableOfContents.gen.js b/themes/V3/5ePHB/snippets/tableOfContents.gen.js index 7c5cae7d3..0ae0213cc 100644 --- a/themes/V3/5ePHB/snippets/tableOfContents.gen.js +++ b/themes/V3/5ePHB/snippets/tableOfContents.gen.js @@ -95,57 +95,27 @@ const getTOC = ()=>{ return res; }; +const ToCIterate = (entries, curDepth=0)=>{ + const levelPad = ['- ###', ' - ####', ' - ####', ' - ####', ' - ####', ' - ####']; + const toc = []; + if(entries.title !== null){ + toc.push(`${levelPad[curDepth]} [{{ ${entries.title}}}{{ ${entries.page}}}](#p${entries.page})`); + } + if(entries.children.length) { + _.each(entries.children, (entry, idx)=>{ + const children = ToCIterate(entry, curDepth+1); + if(children.length) { + toc.push(...children); + } + }); + } + return toc; +}; + module.exports = function(props){ const TOC = getTOC(); const markdown = _.reduce(TOC, (r, g1, idx1)=>{ - if(g1.title !== null) { - r.push(`- ### [{{ ${g1.title}}}{{ ${g1.page}}}](#p${g1.page})`); - } - if(g1.children.length){ - _.each(g1.children, (g2, idx2)=>{ - if(g2.title !== null) { - r.push(` - #### [{{ ${g2.title}}}{{ ${g2.page}}}](#p${g2.page})`); - } - if(g2.children.length){ - _.each(g2.children, (g3, idx3)=>{ - if(g3.title !== null) { - if(g2.title !== null) { - r.push(` - #### [{{ ${g3.title}}}{{ ${g3.page}}}](#p${g3.page})`); - } else { // Don't over-indent if no level-2 parent entry - r.push(` - #### [{{ ${g3.title}}}{{ ${g3.page}}}](#p${g3.page})`); - } - } - _.each(g3.children, (g4, idx4)=>{ - if(g4.title !== null) { - if(g3.title !== null) { - r.push(` - #### [{{ ${g4.title}}}{{ ${g4.page}}}](#p${g4.page})`); - } else { // Don't over-indent if no level-3 parent entry - r.push(` - #### [{{ ${g4.title}}}{{ ${g4.page}}}](#p${g4.page})`); - } - } - _.each(g4.children, (g5, idx5)=>{ - if(g5.title !== null) { - if(g4.title !== null) { - r.push(` - #### [{{ ${g5.title}}}{{ ${g5.page}}}](#p${g5.page})`); - } else { // Don't over-indent if no level-4 parent entry - r.push(` - #### [{{ ${g5.title}}}{{ ${g5.page}}}](#p${g5.page})`); - } - } - _.each(g5.children, (g6, idx6)=>{ - if(g6.title !== null) { - if(g5.title !== null) { - r.push(` - #### [{{ ${g6.title}}}{{ ${g6.page}}}](#p${g6.page})`); - } else { // Don't over-indent if no level-5 parent entry - r.push(` - #### [{{ ${g6.title}}}{{ ${g6.page}}}](#p${g6.page})`); - } - } - }); - }); - }); - }); - } - }); - } + r.push(ToCIterate(g1).join('\n')); return r; }, []).join('\n'); From cdf5b29ac2c6e902bb4a64992a04d4087ce8599b Mon Sep 17 00:00:00 2001 From: David Bolack Date: Mon, 25 Mar 2024 19:38:26 -0500 Subject: [PATCH 12/28] Remove !important from toc.h4/h5/h6 --TOC --- themes/V3/5ePHB/style.less | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/themes/V3/5ePHB/style.less b/themes/V3/5ePHB/style.less index 9898bff0b..1dd41237c 100644 --- a/themes/V3/5ePHB/style.less +++ b/themes/V3/5ePHB/style.less @@ -832,7 +832,7 @@ h6, &:hover { text-decoration : underline; } } h1, h2, h3, h4, h5, h6 { - --TOC: exclude !important; + --TOC: exclude; } h4 { margin-top : 0.2cm; From 7690fb9287c4576bb75cd80cf6615ba65f7ff3c6 Mon Sep 17 00:00:00 2001 From: David Bolack Date: Tue, 26 Mar 2024 09:39:15 -0500 Subject: [PATCH 13/28] Return .addToC for inline mustaches --- themes/V3/5ePHB/style.less | 2 ++ 1 file changed, 2 insertions(+) diff --git a/themes/V3/5ePHB/style.less b/themes/V3/5ePHB/style.less index 1dd41237c..849786b3e 100644 --- a/themes/V3/5ePHB/style.less +++ b/themes/V3/5ePHB/style.less @@ -815,6 +815,8 @@ h6, h6 { --TOC: include; } } +.addToC { --TOC: include; } + .page { &:has(.toc)::after { display : none; } .toc { From 90ce48b170501cacc125c0ed4c74fbb469b15c2b Mon Sep 17 00:00:00 2001 From: David Bolack Date: Sat, 20 Apr 2024 21:46:32 -0500 Subject: [PATCH 14/28] Adapt Recursive Toc function from 3254 --- .../V3/5ePHB/snippets/tableOfContents.gen.js | 128 +++++++----------- 1 file changed, 48 insertions(+), 80 deletions(-) diff --git a/themes/V3/5ePHB/snippets/tableOfContents.gen.js b/themes/V3/5ePHB/snippets/tableOfContents.gen.js index 0ae0213cc..56873aeb6 100644 --- a/themes/V3/5ePHB/snippets/tableOfContents.gen.js +++ b/themes/V3/5ePHB/snippets/tableOfContents.gen.js @@ -1,100 +1,67 @@ const _ = require('lodash'); const dedent = require('dedent-tabs').default; -const getTOC = ()=>{ - const add1 = (title, page)=>{ - res.push({ - title : title, - page : page, - children : [] - }); - }; - const add2 = (title, page)=>{ - if(!_.last(res)) add1(null, page); - _.last(res).children.push({ - title : title, - page : page, - children : [] - }); - }; - const add3 = (title, page)=>{ - if(!_.last(res)) add1(null, page); - if(!_.last(_.last(res).children)) add2(null, page); - _.last(_.last(res).children).children.push({ - title : title, - page : page, - children : [] - }); - }; - const add4 = (title, page)=>{ - if(!_.last(res)) add1(null, page); - if(!_.last(_.last(res).children)) add2(null, page); - if(!_.last(!_.last(_.last(res).children))) add3(null, page); - _.last(_.last(_.last(res).children).children).children.push({ - title : title, - page : page, - children : [] - }); - }; - const add5 = (title, page)=>{ - if(!_.last(res)) add1(null, page); - if(!_.last(_.last(res).children)) add2(null, page); - if(!_.last(!_.last(_.last(res).children))) add3(null, page); - if(!_.last(!_.last(!_.last(_.last(res).children)))) add4(null, page); - _.last(_.last(_.last(_.last(res).children).children).children).children.push({ - title : title, - page : page, - children : [] - }); - }; - const add6 = (title, page)=>{ - if(!_.last(res)) add1(null, page); - if(!_.last(_.last(res).children)) add2(null, page); - if(!_.last(!_.last(_.last(res).children))) add3(null, page); - if(!_.last(!_.last(!_.last(_.last(res).children)))) add4(null, page); - if(!_.last(!_.last(!_.last(!_.last(_.last(res).children))))) add5(null, page); - _.last(_.last(_.last(_.last(_.last(res).children).children).children).children).children.push({ - title : title, - page : page, - children : [] - }); +const getTOC = (pages)=>{ + + const recursiveAdd = (title, page, targetDepth, child, curDepth=0)=>{ + console.log(curDepth); + if(curDepth > 5) return; // Something went wrong. + if(curDepth == targetDepth) { + child.push({ + title : title, + page : page + 1, + children : [] + }); + } else { + console.log(typeof child); + child.push({ + title : null, + page : page + 1, + children : [] + }); + console.log(_.last(child)); + console.log(_.last(child).children); + recursiveAdd(title, page, targetDepth, _.last(child).children, curDepth+1,); + } }; const res = []; - const iframe = document.getElementById('BrewRenderer'); - const iframeDocument = iframe.contentDocument || iframe.contentWindow.document; - const headings = iframeDocument.querySelectorAll('h1, h2, h3, h4, h5, h6'); - _.each(headings, (heading)=>{ - const onPage = parseInt(heading.closest('.page,.phb').id?.replace(/^p/, '')); - const ToCExclude = getComputedStyle(heading).getPropertyValue('--TOC'); - if(ToCExclude != 'exclude') { - if(!isNaN(onPage)) { - const headingText = heading.innerText.trim(); - if(heading.tagName == 'H1') { - add1(headingText, onPage); + _.each(pages, (page, pageNum)=>{ + if(!page.includes("{{frontCover}}") && !page.includes("{{insideCover}}") && !page.includes("{{partCover}}") && !page.includes("{{backCover}}")) { + const lines = page.split('\n'); + _.each(lines, (line)=>{ + if(_.startsWith(line, '# ')){ + const title = line.replace('# ', ''); + recursiveAdd(title, pageNum, 0, res); } - if(heading.tagName == 'H2') { - add2(headingText, onPage); + if(_.startsWith(line, '## ')){ + const title = line.replace('## ', ''); + recursiveAdd(title, pageNum, 1, res); } - if(heading.tagName == 'H3') { - add3(headingText, onPage); + if(_.startsWith(line, '### ')){ + const title = line.replace('### ', ''); + recursiveAdd(title, pageNum, 2, res); } - if(heading.tagName == 'H4') { - add4(headingText, onPage); + if(_.startsWith(line, '#### ')){ + const title = line.replace('#### ', ''); + recursiveAdd(title, pageNum, 3, res); } - if(heading.tagName == 'H5') { - add5(headingText, onPage); + if(_.startsWith(line, '##### ')){ + const title = line.replace('##### ', ''); + recursiveAdd(title, pageNum, 4, res); } - if(heading.tagName == 'H6') { - add6(headingText, onPage); + if(_.startsWith(line, '##### ')){ + const title = line.replace('##### ', ''); + recursiveAdd(title, pageNum, 5, res); } - } + }); } }); return res; }; + const ToCIterate = (entries, curDepth=0)=>{ const levelPad = ['- ###', ' - ####', ' - ####', ' - ####', ' - ####', ' - ####']; const toc = []; @@ -113,7 +80,8 @@ const ToCIterate = (entries, curDepth=0)=>{ }; module.exports = function(props){ - const TOC = getTOC(); + const pages = props.brew.text.split('\\page'); + const TOC = getTOC(pages); const markdown = _.reduce(TOC, (r, g1, idx1)=>{ r.push(ToCIterate(g1).join('\n')); return r; From 2a148cb138a57a1c6d59eab64fbacd5d15ad3035 Mon Sep 17 00:00:00 2001 From: David Bolack Date: Sat, 20 Apr 2024 21:53:02 -0500 Subject: [PATCH 15/28] Update Menus and standardize CSS Names Update addh4, addh5, addh6 class names to addToCH4, addToCH5, addToCH6 Update menu items for Table of contents with better labels and addToC --- themes/V3/5ePHB/snippets.js | 19 +++++++++++++------ themes/V3/5ePHB/style.less | 6 +++--- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/themes/V3/5ePHB/snippets.js b/themes/V3/5ePHB/snippets.js index c8b3dbde1..081ab3ef3 100644 --- a/themes/V3/5ePHB/snippets.js +++ b/themes/V3/5ePHB/snippets.js @@ -31,23 +31,30 @@ module.exports = [ gen : TableOfContentsGen, }, { - name : 'Include H4', + name : 'Include up to H4', icon : 'fas fa-dice-four', - gen : dedent `{{tocH4 + gen : dedent `{{addToCH4 }}`, }, { - name : 'Include H4, H5', + name : 'Include up to H5', icon : 'fas fa-dice-five', - gen : dedent `{{tocH5 + gen : dedent `{{addToCH5 }}`, }, { - name : 'Include H4-H6', + name : 'Include up to H6', icon : 'fas fa-dice-six', - gen : dedent `{{tocH6 + gen : dedent `{{addToCH6 }}`, }, + { + name : 'Include in ToC', + icon : 'fas fa-dice-six', + gen : dedent `{{addToC + }}`, + + } ] }, { diff --git a/themes/V3/5ePHB/style.less b/themes/V3/5ePHB/style.less index f90396401..9c0059ba8 100644 --- a/themes/V3/5ePHB/style.less +++ b/themes/V3/5ePHB/style.less @@ -802,14 +802,14 @@ h6, .noToC, .toc { --TOC: exclude; } -.tocH4 { +.addToCH4 { h4 { --TOC: include; } } -.tocH5 { +.addToCH5 { h4 { --TOC: include; } h5 { --TOC: include; } } -.tocH6 { +.addToCH6 { h4 { --TOC: include; } h5 { --TOC: include; } h6 { --TOC: include; } From c0beae6e46e2b52918dedaebdf27669955979e25 Mon Sep 17 00:00:00 2001 From: David Bolack Date: Sun, 12 May 2024 11:49:30 -0500 Subject: [PATCH 16/28] Remove redundant class declaration for ToC --- themes/V3/5ePHB/style.less | 3 --- 1 file changed, 3 deletions(-) diff --git a/themes/V3/5ePHB/style.less b/themes/V3/5ePHB/style.less index c65ed852f..06bc7b1ac 100644 --- a/themes/V3/5ePHB/style.less +++ b/themes/V3/5ePHB/style.less @@ -825,9 +825,6 @@ h6, text-decoration : none; &:hover { text-decoration : underline; } } - h1, h2, h3, h4, h5, h6 { - --TOC: exclude; - } h4 { margin-top : 0.2cm; line-height : 0.4cm; From afb5ccec8169ef960bae5b24741185ba2c94bf1b Mon Sep 17 00:00:00 2001 From: David Bolack Date: Sun, 12 May 2024 12:00:55 -0500 Subject: [PATCH 17/28] Slight Rearrange of ToC theme names and menu Reorders ToC inclusion options with slight relabel for clarity. Changes assumptions on H4, H5, and H6 snippets to assume H1-H3 class should be explicitly stated. change naming of addToToCH# to tocH# more explicitly define .addToC to h1 to h3 changes for --TOC var. --- themes/V3/5ePHB/snippets.js | 24 ++++++++++++------------ themes/V3/5ePHB/style.less | 12 ++++++++---- 2 files changed, 20 insertions(+), 16 deletions(-) diff --git a/themes/V3/5ePHB/snippets.js b/themes/V3/5ePHB/snippets.js index 081ab3ef3..149517fbb 100644 --- a/themes/V3/5ePHB/snippets.js +++ b/themes/V3/5ePHB/snippets.js @@ -31,29 +31,29 @@ module.exports = [ gen : TableOfContentsGen, }, { - name : 'Include up to H4', - icon : 'fas fa-dice-four', - gen : dedent `{{addToCH4 + name : 'Include in ToC up to H3', + icon : 'fas fa-dice-six', + gen : dedent `{{addToC }}`, + }, { - name : 'Include up to H5', - icon : 'fas fa-dice-five', - gen : dedent `{{addToCH5 + name : 'Include in ToC up to H4', + icon : 'fas fa-dice-four', + gen : dedent `{{addToC,tocH4 }}`, }, { - name : 'Include up to H6', - icon : 'fas fa-dice-six', - gen : dedent `{{addToCH6 + name : 'Include in ToC up to H5', + icon : 'fas fa-dice-five', + gen : dedent `{{addToC,tocH5 }}`, }, { - name : 'Include in ToC', + name : 'Include in ToC up to H6', icon : 'fas fa-dice-six', - gen : dedent `{{addToC + gen : dedent `{{addToC,tocH6 }}`, - } ] }, diff --git a/themes/V3/5ePHB/style.less b/themes/V3/5ePHB/style.less index 06bc7b1ac..41318cfe6 100644 --- a/themes/V3/5ePHB/style.less +++ b/themes/V3/5ePHB/style.less @@ -794,20 +794,24 @@ h6, .noToC, .toc { --TOC: exclude; } -.addToCH4 { +.tocH4 { h4 { --TOC: include; } } -.addToCH5 { +.tocH5 { h4 { --TOC: include; } h5 { --TOC: include; } } -.addToCH6 { +.tocH6 { h4 { --TOC: include; } h5 { --TOC: include; } h6 { --TOC: include; } } -.addToC { --TOC: include; } +.addToC { + h1 {--TOC: include; } + h2 {--TOC: include; } + h3 {--TOC: include; } +} .page { &:has(.toc)::after { display : none; } From 1773e77cb9d0d32f1be509d2b6ce9ea2293a9c00 Mon Sep 17 00:00:00 2001 From: David Bolack Date: Wed, 22 May 2024 11:47:12 -0500 Subject: [PATCH 18/28] Fix missed issues with converting to delightfully recursive function --- .../V3/5ePHB/snippets/tableOfContents.gen.js | 52 +++++++------------ 1 file changed, 19 insertions(+), 33 deletions(-) diff --git a/themes/V3/5ePHB/snippets/tableOfContents.gen.js b/themes/V3/5ePHB/snippets/tableOfContents.gen.js index 56873aeb6..6bb87cbf1 100644 --- a/themes/V3/5ePHB/snippets/tableOfContents.gen.js +++ b/themes/V3/5ePHB/snippets/tableOfContents.gen.js @@ -4,7 +4,6 @@ const dedent = require('dedent-tabs').default; const getTOC = (pages)=>{ const recursiveAdd = (title, page, targetDepth, child, curDepth=0)=>{ - console.log(curDepth); if(curDepth > 5) return; // Something went wrong. if(curDepth == targetDepth) { child.push({ @@ -13,49 +12,36 @@ const getTOC = (pages)=>{ children : [] }); } else { - console.log(typeof child); child.push({ title : null, page : page + 1, children : [] }); - console.log(_.last(child)); - console.log(_.last(child).children); recursiveAdd(title, page, targetDepth, _.last(child).children, curDepth+1,); } }; const res = []; - _.each(pages, (page, pageNum)=>{ - if(!page.includes("{{frontCover}}") && !page.includes("{{insideCover}}") && !page.includes("{{partCover}}") && !page.includes("{{backCover}}")) { - const lines = page.split('\n'); - _.each(lines, (line)=>{ - if(_.startsWith(line, '# ')){ - const title = line.replace('# ', ''); - recursiveAdd(title, pageNum, 0, res); - } - if(_.startsWith(line, '## ')){ - const title = line.replace('## ', ''); - recursiveAdd(title, pageNum, 1, res); - } - if(_.startsWith(line, '### ')){ - const title = line.replace('### ', ''); - recursiveAdd(title, pageNum, 2, res); - } - if(_.startsWith(line, '#### ')){ - const title = line.replace('#### ', ''); - recursiveAdd(title, pageNum, 3, res); - } - if(_.startsWith(line, '##### ')){ - const title = line.replace('##### ', ''); - recursiveAdd(title, pageNum, 4, res); - } - if(_.startsWith(line, '##### ')){ - const title = line.replace('##### ', ''); - recursiveAdd(title, pageNum, 5, res); - } - }); + const iframe = document.getElementById('BrewRenderer'); + 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 excludedPages = []; + + // Build a list of excluded pages. + _.each(exclusionElements, (e)=>{ + const onPage = parseInt(e.closest('.page,.phb').id?.replace(/^p/, '')); + if(!excludedPages.includes(onPage)) excludedPages.push(onPage); + }); + + _.each(headings, (heading)=>{ + const onPage = parseInt(heading.closest('.page,.phb').id?.replace(/^p/, '')); + const ToCExclude = getComputedStyle(heading).getPropertyValue('--TOC'); + + if((ToCExclude != 'exclude') && (!excludedPages.includes(onPage))) { + recursiveAdd(heading.innerText.trim(), onPage, headerDepth.indexOf(heading.tagName), res); } }); return res; From d9d4d74b713489d3eba5c9e0ff515e57f38ee5bf Mon Sep 17 00:00:00 2001 From: David Bolack Date: Wed, 22 May 2024 12:44:19 -0500 Subject: [PATCH 19/28] Add CR wrappers around addTOC snippet insertions. --- themes/V3/5ePHB/snippets.js | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/themes/V3/5ePHB/snippets.js b/themes/V3/5ePHB/snippets.js index 149517fbb..5c93c8004 100644 --- a/themes/V3/5ePHB/snippets.js +++ b/themes/V3/5ePHB/snippets.js @@ -33,27 +33,27 @@ module.exports = [ { name : 'Include in ToC up to H3', icon : 'fas fa-dice-six', - gen : dedent `{{addToC - }}`, + gen : dedent `\n{{addToC + }}\n`, }, { name : 'Include in ToC up to H4', icon : 'fas fa-dice-four', - gen : dedent `{{addToC,tocH4 - }}`, + gen : dedent `\n{{addToC,tocH4 + }}\n`, }, { name : 'Include in ToC up to H5', icon : 'fas fa-dice-five', - gen : dedent `{{addToC,tocH5 - }}`, + gen : dedent `\n{{addToC,tocH5 + }}\n`, }, { name : 'Include in ToC up to H6', icon : 'fas fa-dice-six', - gen : dedent `{{addToC,tocH6 - }}`, + gen : dedent `\n{{addToC,tocH6 + }}\n`, } ] }, From 3ae5d4c1e311067ef75541bb4aa036fc47ce1c99 Mon Sep 17 00:00:00 2001 From: David Bolack Date: Wed, 22 May 2024 16:30:12 -0500 Subject: [PATCH 20/28] 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 | 32 ++++++++----------- 3 files changed, 24 insertions(+), 25 deletions(-) diff --git a/themes/V3/5ePHB/snippets.js b/themes/V3/5ePHB/snippets.js index 5c93c8004..2c18354b8 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 6bb87cbf1..9e8ed8040 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 0ba6062e9..68ea5eda9 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; } -} - -.addToC { - h1 {--TOC: include; } - h2 {--TOC: include; } - h3 {--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; } + +.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; } From b496ef35978bdd3b616532d9563fad990327f01d Mon Sep 17 00:00:00 2001 From: David Bolack Date: Wed, 22 May 2024 16:34:00 -0500 Subject: [PATCH 21/28] Remove completely redundant checks for class based exclusion from ToC Snippet --- themes/V3/5ePHB/snippets/tableOfContents.gen.js | 15 +-------------- 1 file changed, 1 insertion(+), 14 deletions(-) diff --git a/themes/V3/5ePHB/snippets/tableOfContents.gen.js b/themes/V3/5ePHB/snippets/tableOfContents.gen.js index 9e8ed8040..66aab50bc 100644 --- a/themes/V3/5ePHB/snippets/tableOfContents.gen.js +++ b/themes/V3/5ePHB/snippets/tableOfContents.gen.js @@ -27,25 +27,12 @@ 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 backCover'); - const excludedPages = []; - - // Build a list of excluded pages. - _.each(exclusionElements, (e)=>{ - const onPage = parseInt(e.closest('.page,.phb').id?.replace(/^p/, '')); - if(!excludedPages.includes(onPage)) excludedPages.push(onPage); - }); _.each(headings, (heading)=>{ const onPage = parseInt(heading.closest('.page,.phb').id?.replace(/^p/, '')); const ToCExclude = getComputedStyle(heading).getPropertyValue('--TOC'); - if(heading.tagName == 'H1') { - console.log(heading); - console.log(ToCExclude); - } - - if(((ToCExclude != 'exclude') && (!excludedPages.includes(onPage)))) { + if(ToCExclude != 'exclude') { recursiveAdd(heading.innerText.trim(), onPage, headerDepth.indexOf(heading.tagName), res); } }); From 0df53daa4c2dbb09468e25309e23912a6fae14ee Mon Sep 17 00:00:00 2001 From: David Bolack Date: Wed, 22 May 2024 17:25:52 -0500 Subject: [PATCH 22/28] Another attempt at clearer classnames for the Table of contents snippet --- themes/V3/5ePHB/snippets.js | 8 ++++---- themes/V3/5ePHB/style.less | 25 ++++++++++++------------- 2 files changed, 16 insertions(+), 17 deletions(-) diff --git a/themes/V3/5ePHB/snippets.js b/themes/V3/5ePHB/snippets.js index 2c18354b8..0aba0d11e 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{{tocH3 + gen : dedent `\n{{tocAddH1H3 }}\n`, }, { name : 'Include in ToC up to H4', icon : 'fas fa-dice-four', - gen : dedent `\n{{tocH4 + gen : dedent `\n{{tocAddH1H4 }}\n`, }, { name : 'Include in ToC up to H5', icon : 'fas fa-dice-five', - gen : dedent `\n{{tocH5 + gen : dedent `\n{{tocAddH1H5 }}\n`, }, { name : 'Include in ToC up to H6', icon : 'fas fa-dice-six', - gen : dedent `\n{{tocH6 + gen : dedent `\n{{tocAddH1H6 }}\n`, } ] diff --git a/themes/V3/5ePHB/style.less b/themes/V3/5ePHB/style.less index 68ea5eda9..0f34585f7 100644 --- a/themes/V3/5ePHB/style.less +++ b/themes/V3/5ePHB/style.less @@ -798,19 +798,18 @@ h6, .noToC, .toc { --TOC: exclude; } -.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; } - -.tocIncludeH1 h1 {--TOC: include; } -.tocIncludeH2 h2 {--TOC: include; } -.tocIncludeH3 h3 {--TOC: include; } -.tocIncludeH4 h4 {--TOC: include; } -.tocIncludeH5 h5 {--TOC: include; } -.tocIncludeH6 h6 {--TOC: include; } +.tocAddH1H2 :is(h1, h2) {--TOC: include; } +.tocAddH1H3 :is(h1, h2, h3) {--TOC: include; } +.tocAddH1H4 :is(h1, h2, h3, h4) {--TOC: include; } +.tocAddH1H5 :is(h1, h2, h3, h4, h5) {--TOC: include; } +.tocAddH1H6 :is(h1, h2, h3, h4, h5, h6) {--TOC: include; } + +.tocAddH1 h1 {--TOC: include; } +.tocAddH2 h2 {--TOC: include; } +.tocAddH3 h3 {--TOC: include; } +.tocAddH4 h4 {--TOC: include; } +.tocAddH5 h5 {--TOC: include; } +.tocAddH6 h6 {--TOC: include; } .page { &:has(.toc)::after { display : none; } From 7cef4316d78a19ef35ae383cc6cd9b7ad815fc60 Mon Sep 17 00:00:00 2001 From: David Bolack Date: Wed, 22 May 2024 21:04:32 -0500 Subject: [PATCH 23/28] Flag Table of Contents as "Experimental" --- themes/V3/5ePHB/snippets.js | 16 +++++++++------- themes/V3/5ePHB/snippets/tableOfContents.gen.js | 2 +- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/themes/V3/5ePHB/snippets.js b/themes/V3/5ePHB/snippets.js index 0aba0d11e..adcfe95a5 100644 --- a/themes/V3/5ePHB/snippets.js +++ b/themes/V3/5ePHB/snippets.js @@ -21,14 +21,16 @@ module.exports = [ view : 'text', snippets : [ { - name : 'Table of Contents', - icon : 'fas fa-book', - gen : TableOfContentsGen, - subsnippets : [ + name : 'Table of Contents', + icon : 'fas fa-book', + gen : TableOfContentsGen, + experimental : true, + subsnippets : [ { - name : 'Table of Contents', - icon : 'fas fa-book', - gen : TableOfContentsGen, + name : 'Table of Contents', + icon : 'fas fa-book', + gen : TableOfContentsGen, + experimental : true }, { name : 'Include in ToC up to H3', diff --git a/themes/V3/5ePHB/snippets/tableOfContents.gen.js b/themes/V3/5ePHB/snippets/tableOfContents.gen.js index 66aab50bc..c33530bd7 100644 --- a/themes/V3/5ePHB/snippets/tableOfContents.gen.js +++ b/themes/V3/5ePHB/snippets/tableOfContents.gen.js @@ -29,7 +29,7 @@ const getTOC = (pages)=>{ const headerDepth = ['H1', 'H2', 'H3', 'H4', 'H5', 'H6']; _.each(headings, (heading)=>{ - const onPage = parseInt(heading.closest('.page,.phb').id?.replace(/^p/, '')); + const onPage = parseInt(heading.closest('.page').id?.replace(/^p/, '')); const ToCExclude = getComputedStyle(heading).getPropertyValue('--TOC'); if(ToCExclude != 'exclude') { From 62ed026757c327a4673c68f874238e3c4928607d Mon Sep 17 00:00:00 2001 From: David Bolack Date: Wed, 22 May 2024 21:25:10 -0500 Subject: [PATCH 24/28] Hopeflly final class renaming sessions. --- themes/V3/5ePHB/snippets.js | 8 ++++---- themes/V3/5ePHB/style.less | 24 ++++++++++++------------ 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/themes/V3/5ePHB/snippets.js b/themes/V3/5ePHB/snippets.js index adcfe95a5..01ec1c700 100644 --- a/themes/V3/5ePHB/snippets.js +++ b/themes/V3/5ePHB/snippets.js @@ -35,26 +35,26 @@ module.exports = [ { name : 'Include in ToC up to H3', icon : 'fas fa-dice-six', - gen : dedent `\n{{tocAddH1H3 + gen : dedent `\n{{tocDepthH3 }}\n`, }, { name : 'Include in ToC up to H4', icon : 'fas fa-dice-four', - gen : dedent `\n{{tocAddH1H4 + gen : dedent `\n{{tocDepthH4 }}\n`, }, { name : 'Include in ToC up to H5', icon : 'fas fa-dice-five', - gen : dedent `\n{{tocAddH1H5 + gen : dedent `\n{{tocDepthH5 }}\n`, }, { name : 'Include in ToC up to H6', icon : 'fas fa-dice-six', - gen : dedent `\n{{tocAddH1H6 + gen : dedent `\n{{tocDepthH6 }}\n`, } ] diff --git a/themes/V3/5ePHB/style.less b/themes/V3/5ePHB/style.less index 0f34585f7..674b29364 100644 --- a/themes/V3/5ePHB/style.less +++ b/themes/V3/5ePHB/style.less @@ -798,18 +798,18 @@ h6, .noToC, .toc { --TOC: exclude; } -.tocAddH1H2 :is(h1, h2) {--TOC: include; } -.tocAddH1H3 :is(h1, h2, h3) {--TOC: include; } -.tocAddH1H4 :is(h1, h2, h3, h4) {--TOC: include; } -.tocAddH1H5 :is(h1, h2, h3, h4, h5) {--TOC: include; } -.tocAddH1H6 :is(h1, h2, h3, h4, h5, h6) {--TOC: include; } - -.tocAddH1 h1 {--TOC: include; } -.tocAddH2 h2 {--TOC: include; } -.tocAddH3 h3 {--TOC: include; } -.tocAddH4 h4 {--TOC: include; } -.tocAddH5 h5 {--TOC: include; } -.tocAddH6 h6 {--TOC: include; } +.tocDepthH2 :is(h1, h2) {--TOC: include; } +.tocDepthH3 :is(h1, h2, h3) {--TOC: include; } +.tocDepthH4 :is(h1, h2, h3, h4) {--TOC: include; } +.tocDepthH5 :is(h1, h2, h3, h4, h5) {--TOC: include; } +.tocDepthH6 :is(h1, h2, h3, h4, h5, h6) {--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; } From fc22e6cd5376f5d8cf0a5eae72585105502c601f Mon Sep 17 00:00:00 2001 From: David Bolack Date: Wed, 22 May 2024 23:17:22 -0500 Subject: [PATCH 25/28] Smidge of documentation --- themes/V3/5ePHB/style.less | 1 + 1 file changed, 1 insertion(+) diff --git a/themes/V3/5ePHB/style.less b/themes/V3/5ePHB/style.less index 674b29364..7ef50df34 100644 --- a/themes/V3/5ePHB/style.less +++ b/themes/V3/5ePHB/style.less @@ -788,6 +788,7 @@ // *****************************/ // Default Exclusions +// Anything not exlcuded is included, default Headers are H1, H2, and H3. h4, h5, h6, From 8fc224e9a10a18bf6c30dc732a6fb8204616596e Mon Sep 17 00:00:00 2001 From: Trevor Buckner Date: Tue, 28 May 2024 17:33:52 -0400 Subject: [PATCH 26/28] Update themes/V3/5ePHB/snippets.js --- themes/V3/5ePHB/snippets.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/themes/V3/5ePHB/snippets.js b/themes/V3/5ePHB/snippets.js index 01ec1c700..d5f37ac65 100644 --- a/themes/V3/5ePHB/snippets.js +++ b/themes/V3/5ePHB/snippets.js @@ -34,7 +34,7 @@ module.exports = [ }, { name : 'Include in ToC up to H3', - icon : 'fas fa-dice-six', + icon : 'fas fa-dice-three', gen : dedent `\n{{tocDepthH3 }}\n`, From fbe65a4e93ad86309eb1bc3ea41957937d7c9ece Mon Sep 17 00:00:00 2001 From: David Bolack Date: Sat, 1 Jun 2024 00:32:25 -0500 Subject: [PATCH 27/28] Resolve indentation errors in TOC Generation, adjust partCover class This fixes an error in the recusion that was failing to add children under existing parents. Index generation now does not overindent when levels are skipped. PartCover less code as suggesred by CC. --- themes/V3/5ePHB/snippets/tableOfContents.gen.js | 16 +++++++++------- themes/V3/5ePHB/style.less | 7 +++++++ 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/themes/V3/5ePHB/snippets/tableOfContents.gen.js b/themes/V3/5ePHB/snippets/tableOfContents.gen.js index c33530bd7..1ec778944 100644 --- a/themes/V3/5ePHB/snippets/tableOfContents.gen.js +++ b/themes/V3/5ePHB/snippets/tableOfContents.gen.js @@ -12,11 +12,13 @@ const getTOC = (pages)=>{ children : [] }); } else { - child.push({ - title : null, - page : page + 1, - children : [] - }); + if(child.length == 0) { + child.push({ + title : null, + page : page + 1, + children : [] + }); + } recursiveAdd(title, page, targetDepth, _.last(child).children, curDepth+1,); } }; @@ -41,14 +43,14 @@ const getTOC = (pages)=>{ const ToCIterate = (entries, curDepth=0)=>{ - const levelPad = ['- ###', ' - ####', ' - ####', ' - ####', ' - ####', ' - ####']; + const levelPad = ['- ###', ' - ####', ' - ', ' - ', ' - ', ' - ']; const toc = []; if(entries.title !== null){ toc.push(`${levelPad[curDepth]} [{{ ${entries.title}}}{{ ${entries.page}}}](#p${entries.page})`); } if(entries.children.length) { _.each(entries.children, (entry, idx)=>{ - const children = ToCIterate(entry, curDepth+1); + const children = ToCIterate(entry, entry.title == null ? curDepth : curDepth+1); if(children.length) { toc.push(...children); } diff --git a/themes/V3/5ePHB/style.less b/themes/V3/5ePHB/style.less index 7ef50df34..8b805b760 100644 --- a/themes/V3/5ePHB/style.less +++ b/themes/V3/5ePHB/style.less @@ -812,6 +812,13 @@ h6, .tocIncludeH5 h5 {--TOC: include; } .tocIncludeH6 h6 {--TOC: include; } +.page:has(.partCover) { + --TOC: exclude; + &h1 { + --TOC: include; + } + } + .page { &:has(.toc)::after { display : none; } .toc { From 9886200fa901ef1f0f3dccee68138acf8c1dc29f Mon Sep 17 00:00:00 2001 From: Trevor Buckner Date: Fri, 28 Jun 2024 09:39:49 -0400 Subject: [PATCH 28/28] Fix partCover H1 inclusion rule --- themes/V3/5ePHB/style.less | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/themes/V3/5ePHB/style.less b/themes/V3/5ePHB/style.less index 8b805b760..f8a14f46e 100644 --- a/themes/V3/5ePHB/style.less +++ b/themes/V3/5ePHB/style.less @@ -814,7 +814,7 @@ h6, .page:has(.partCover) { --TOC: exclude; - &h1 { + & h1 { --TOC: include; } }