mirror of
https://github.com/naturalcrit/homebrewery.git
synced 2026-01-17 03:42:43 +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:
@@ -1,7 +1,7 @@
|
|||||||
const _ = require('lodash');
|
const _ = require('lodash');
|
||||||
const dedent = require('dedent-tabs').default;
|
const dedent = require('dedent-tabs').default;
|
||||||
|
|
||||||
const getTOC = (pages)=>{
|
const getTOC = ()=>{
|
||||||
const add1 = (title, page)=>{
|
const add1 = (title, page)=>{
|
||||||
res.push({
|
res.push({
|
||||||
title : title,
|
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 = [];
|
const res = [];
|
||||||
_.each(pages, (page, pageNum)=>{
|
const iframe = document.getElementById('BrewRenderer');
|
||||||
if(!page.includes("{{frontCover}}") && !page.includes("{{insideCover}}") && !page.includes("{{partCover}}") && !page.includes("{{backCover}}")) {
|
const iframeDocument = iframe.contentDocument || iframe.contentWindow.document;
|
||||||
const lines = page.split('\n');
|
const headings = iframeDocument.querySelectorAll('h1, h2, h3');
|
||||||
_.each(lines, (line)=>{
|
|
||||||
if(_.startsWith(line, '# ')){
|
_.each(headings, (heading)=>{
|
||||||
const title = line.replace('# ', '');
|
const onPage = getParentPageNumber(heading);
|
||||||
add1(title, pageNum);
|
if(getComputedStyle(heading).getPropertyValue('--TOC') != 'exclude') {
|
||||||
|
if(onPage != -1) {
|
||||||
|
const headingText = heading.innerText;
|
||||||
|
if(heading.tagName == 'H1') {
|
||||||
|
add1(headingText, onPage);
|
||||||
}
|
}
|
||||||
if(_.startsWith(line, '## ')){
|
if(heading.tagName == 'H2') {
|
||||||
const title = line.replace('## ', '');
|
add2(headingText, onPage);
|
||||||
add2(title, pageNum);
|
|
||||||
}
|
}
|
||||||
if(_.startsWith(line, '### ')){
|
if(heading.tagName == 'H3') {
|
||||||
const title = line.replace('### ', '');
|
add3(headingText, onPage);
|
||||||
add3(title, pageNum);
|
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
return res;
|
return res;
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports = function(props){
|
module.exports = function(props){
|
||||||
const pages = props.brew.text.split('\\page');
|
const TOC = getTOC();
|
||||||
const TOC = getTOC(pages);
|
|
||||||
const markdown = _.reduce(TOC, (r, g1, idx1)=>{
|
const markdown = _.reduce(TOC, (r, g1, idx1)=>{
|
||||||
if(g1.title !== null) {
|
if(g1.title !== null) {
|
||||||
r.push(`- ### [{{ ${g1.title}}}{{ ${g1.page}}}](#p${g1.page})`);
|
r.push(`- ### [{{ ${g1.title}}}{{ ${g1.page}}}](#p${g1.page})`);
|
||||||
|
|||||||
@@ -314,6 +314,7 @@
|
|||||||
border-image : @monsterBorderImage 14 round;
|
border-image : @monsterBorderImage 14 round;
|
||||||
border-image-outset : 0px 2px;
|
border-image-outset : 0px 2px;
|
||||||
box-shadow : 1px 4px 14px #888888;
|
box-shadow : 1px 4px 14px #888888;
|
||||||
|
--TOC : "exclude";
|
||||||
}
|
}
|
||||||
|
|
||||||
position : relative;
|
position : relative;
|
||||||
@@ -329,11 +330,13 @@
|
|||||||
margin-bottom : 0;
|
margin-bottom : 0;
|
||||||
font-size : 0.304cm; //Monster size and type subtext
|
font-size : 0.304cm; //Monster size and type subtext
|
||||||
}
|
}
|
||||||
|
--TOC : "exclude";
|
||||||
}
|
}
|
||||||
h3 {
|
h3 {
|
||||||
font-family : 'ScalySansSmallCapsRemake';
|
font-family : 'ScalySansSmallCapsRemake';
|
||||||
font-size : 0.45cm;
|
font-size : 0.45cm;
|
||||||
border-bottom : 1.5px solid var(--HB_Color_HeaderText);
|
border-bottom : 1.5px solid var(--HB_Color_HeaderText);
|
||||||
|
--TOC : "exclude";
|
||||||
}
|
}
|
||||||
|
|
||||||
//Triangle dividers
|
//Triangle dividers
|
||||||
|
|||||||
Reference in New Issue
Block a user