Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Table of Contents Snippet exclusion system #3261

Open
wants to merge 58 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 53 commits
Commits
Show all changes
58 commits
Select commit Hold shift + click to select a range
854c216
CSS based ToC exclusion system
dbolacksn Jan 20, 2024
622827e
Fix Exclusion examination
dbolacksn Jan 21, 2024
26c4b1a
Add toggle-on classes.
dbolacksn Jan 21, 2024
b8ee696
Add manual exclusion classes for ToC exclusion.
dbolacksn Jan 24, 2024
02e6a3d
Merge branch 'master' into issue_2994_css_style
dbolack-ab Jan 25, 2024
692205b
Merge branch 'master' into issue_2994_css_style
dbolacksn Jan 30, 2024
85caf0a
Add fixes to account for no page numbers
dbolacksn Jan 30, 2024
75c41f4
Merge branch 'issue_2994_css_style' of github.com:dbolacksn/homebrewe…
dbolacksn Jan 30, 2024
bfd3eff
Merge branch 'master' into issue_2994_css_style
dbolack-ab Feb 8, 2024
41d43e8
Merge branch 'master' into issue_2994_css_style
dbolack-ab Feb 14, 2024
a4d426b
Merge branch 'master' into issue_2994_css_style
dbolacksn Mar 4, 2024
a957ea3
Merge branch 'issue_2994_css_style' of github.com:dbolacksn/homebrewe…
dbolacksn Mar 4, 2024
f0a8020
Merge branch 'master' of github.com:naturalcrit/homebrewery
dbolacksn Mar 20, 2024
9848e4b
Merge branch 'master' of github.com:naturalcrit/homebrewery
dbolacksn Mar 23, 2024
5912788
Merge branch 'master' into issue_2994_css_style
dbolack-ab Mar 23, 2024
6a03be9
Merge branch 'master' into issue_2994_css_style
dbolacksn Mar 23, 2024
1e4f804
Merge branch 'issue_2994_css_style' of github.com:dbolacksn/homebrewe…
dbolack-ab Mar 23, 2024
1705e66
Corrections per PR
dbolack-ab Mar 23, 2024
7ca10ff
Add requested additions to code
dbolacksn Mar 25, 2024
40d0e7e
Trim space off of ToC entries.
dbolacksn Mar 25, 2024
5d87508
Merge branch 'master' of github.com:naturalcrit/homebrewery
dbolacksn Mar 25, 2024
9d3f7fe
Fix H3-H6 entries in ToC generation
dbolacksn Mar 25, 2024
211fe48
Attempt to block H4-h6 from existing ToCs from showing up in a new ToC.
dbolacksn Mar 26, 2024
733b929
Integrate code recursion from 3254.
dbolacksn Mar 26, 2024
cdf5b29
Remove !important from toc.h4/h5/h6 --TOC
dbolacksn Mar 26, 2024
2e54520
Merge branch 'master' into issue_2994_css_style
dbolacksn Mar 26, 2024
7690fb9
Return .addToC for inline mustaches
dbolacksn Mar 26, 2024
b087e84
Merge branch 'master' into issue_2994_css_style
calculuschild Apr 10, 2024
ec5f825
Merge branch 'master' of github.com:naturalcrit/homebrewery
dbolacksn Apr 21, 2024
448af68
Merge branch 'master' into issue_2994_css_style
dbolacksn Apr 21, 2024
90ce48b
Adapt Recursive Toc function from 3254
dbolacksn Apr 21, 2024
9426c6a
Merge branch 'issue_2994_css_style' of github.com:dbolacksn/homebrewe…
dbolacksn Apr 21, 2024
2a148cb
Update Menus and standardize CSS Names
dbolacksn Apr 21, 2024
b86502a
Merge branch 'master' of github.com:naturalcrit/homebrewery
dbolacksn May 1, 2024
9d6076f
Merge branch 'master' of github.com:naturalcrit/homebrewery
dbolacksn May 6, 2024
5494c02
Merge branch 'master' of github.com:naturalcrit/homebrewery
dbolacksn May 12, 2024
9c6ece3
Merge branch 'master' into issue_2994_css_style
dbolacksn May 12, 2024
c0beae6
Remove redundant class declaration for ToC
dbolacksn May 12, 2024
afb5cce
Slight Rearrange of ToC theme names and menu
dbolacksn May 12, 2024
ea03538
Merge branch 'master' of github.com:naturalcrit/homebrewery
dbolacksn May 20, 2024
511c9ff
Merge branch 'master' into issue_2994_css_style
dbolacksn May 20, 2024
1773e77
Fix missed issues with converting to delightfully recursive function
dbolacksn May 22, 2024
f897cbf
Merge branch 'master' of github.com:naturalcrit/homebrewery
dbolacksn May 22, 2024
af82d71
Merge branch 'master' into issue_2994_css_style
dbolacksn May 22, 2024
d9d4d74
Add CR wrappers around addTOC snippet insertions.
dbolacksn May 22, 2024
3ae5d4c
Slight reworking of style naming for Table of Contents
dbolacksn May 22, 2024
b496ef3
Remove completely redundant checks for class based exclusion from ToC…
dbolacksn May 22, 2024
0df53da
Another attempt at clearer classnames for the Table of contents snippet
dbolacksn May 22, 2024
7cef431
Flag Table of Contents as "Experimental"
dbolacksn May 23, 2024
62ed026
Hopeflly final class renaming sessions.
dbolacksn May 23, 2024
fc22e6c
Smidge of documentation
dbolacksn May 23, 2024
98fc007
Merge branch 'master' into issue_2994_css_style
calculuschild May 28, 2024
8fc224e
Update themes/V3/5ePHB/snippets.js
calculuschild May 28, 2024
3875dab
Merge branch 'master' of github.com:naturalcrit/homebrewery
dbolacksn Jun 1, 2024
fbe65a4
Resolve indentation errors in TOC Generation, adjust partCover class
dbolacksn Jun 1, 2024
8c5e68e
Merge branch 'master' into issue_2994_css_style
dbolacksn Jun 1, 2024
d20c9c5
Merge branch 'issue_2994_css_style' of github.com:dbolacksn/homebrewe…
dbolacksn Jun 1, 2024
35ae5e0
Merge branch 'master' into issue_2994_css_style
calculuschild Jun 7, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
40 changes: 37 additions & 3 deletions themes/V3/5ePHB/snippets.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,43 @@ 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,
experimental : true,
subsnippets : [
{
name : 'Table of Contents',
icon : 'fas fa-book',
gen : TableOfContentsGen,
experimental : true
},
{
name : 'Include in ToC up to H3',
icon : 'fas fa-dice-three',
gen : dedent `\n{{tocDepthH3
}}\n`,

},
{
name : 'Include in ToC up to H4',
icon : 'fas fa-dice-four',
gen : dedent `\n{{tocDepthH4
}}\n`,
},
{
name : 'Include in ToC up to H5',
icon : 'fas fa-dice-five',
gen : dedent `\n{{tocDepthH5
}}\n`,
},
{
name : 'Include in ToC up to H6',
icon : 'fas fa-dice-six',
gen : dedent `\n{{tocDepthH6
}}\n`,
}
]
},
{
name : 'Index',
Expand Down
107 changes: 48 additions & 59 deletions themes/V3/5ePHB/snippets/tableOfContents.gen.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,77 +2,66 @@ const _ = require('lodash');
const dedent = require('dedent-tabs').default;

const getTOC = (pages)=>{
const add1 = (title, page)=>{
res.push({
title : title,
page : page + 1,
children : []
});
};
const add2 = (title, page)=>{
if(!_.last(res)) add1(null, page);
_.last(res).children.push({
title : title,
page : page + 1,
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 + 1,
children : []
});

const recursiveAdd = (title, page, targetDepth, child, curDepth=0)=>{
if(curDepth > 5) return; // Something went wrong.
if(curDepth == targetDepth) {
child.push({
title : title,
page : page + 1,
children : []
});
} else {
child.push({
title : null,
page : page + 1,
children : []
});
recursiveAdd(title, page, targetDepth, _.last(child).children, curDepth+1,);
}
};
dbolack-ab marked this conversation as resolved.
Show resolved Hide resolved

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);
}
if(_.startsWith(line, '## ')){
const title = line.replace('## ', '');
add2(title, pageNum);
}
if(_.startsWith(line, '### ')){
const title = line.replace('### ', '');
add3(title, pageNum);
}
});

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'];

_.each(headings, (heading)=>{
const onPage = parseInt(heading.closest('.page').id?.replace(/^p/, ''));
const ToCExclude = getComputedStyle(heading).getPropertyValue('--TOC');

if(ToCExclude != 'exclude') {
recursiveAdd(heading.innerText.trim(), onPage, headerDepth.indexOf(heading.tagName), res);
}
});
return res;
};


const ToCIterate = (entries, curDepth=0)=>{
const levelPad = ['- ###', ' - ####', ' - ####', ' - ####', ' - ####', ' - ####'];
dbolack-ab marked this conversation as resolved.
Show resolved Hide resolved
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 pages = props.brew.text.split('\\page');
const TOC = getTOC(pages);
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(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})`);
dbolack-ab marked this conversation as resolved.
Show resolved Hide resolved
}
});
}
});
}
r.push(ToCIterate(g1).join('\n'));
return r;
}, []).join('\n');

Expand Down
26 changes: 26 additions & 0 deletions themes/V3/5ePHB/style.less
Original file line number Diff line number Diff line change
Expand Up @@ -786,6 +786,32 @@
// *****************************
// * TABLE OF CONTENTS
// *****************************/

// Default Exclusions
// Anything not exlcuded is included, default Headers are H1, H2, and H3.
h4,
h5,
h6,
.page:has(.frontCover),
.page:has(.backCover),
.page:has(.insideCover),
.monster,
ericscheid marked this conversation as resolved.
Show resolved Hide resolved
.noToC,
.toc { --TOC: exclude; }
dbolack-ab marked this conversation as resolved.
Show resolved Hide resolved

dbolack-ab marked this conversation as resolved.
Show resolved Hide resolved
dbolack-ab marked this conversation as resolved.
Show resolved Hide resolved
.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; }
.toc {
Expand Down