0
0
mirror of https://github.com/naturalcrit/homebrewery.git synced 2025-12-31 06:32:37 +00:00

CSS based ToC exclusion system

either I am building the lookup incorrectly or Chrome is not letting me
see variables via computedStyles.
This commit is contained in:
David Bolack
2024-01-20 11:58:17 -06:00
parent 8fc6047127
commit 854c21639a
2 changed files with 33 additions and 17 deletions

View File

@@ -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})`);

View File

@@ -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