mirror of
https://github.com/naturalcrit/homebrewery.git
synced 2026-01-07 09:52:41 +00:00
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.
This commit is contained in:
@@ -21,9 +21,34 @@ module.exports = [
|
|||||||
view : 'text',
|
view : 'text',
|
||||||
snippets : [
|
snippets : [
|
||||||
{
|
{
|
||||||
name : 'Table of Contents',
|
name : 'Table of Contents',
|
||||||
icon : 'fas fa-book',
|
icon : 'fas fa-book',
|
||||||
gen : TableOfContentsGen
|
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',
|
name : 'Index',
|
||||||
|
|||||||
@@ -26,11 +26,44 @@ const getTOC = ()=>{
|
|||||||
children : []
|
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 res = [];
|
||||||
const iframe = document.getElementById('BrewRenderer');
|
const iframe = document.getElementById('BrewRenderer');
|
||||||
const iframeDocument = iframe.contentDocument || iframe.contentWindow.document;
|
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)=>{
|
_.each(headings, (heading)=>{
|
||||||
const onPage = parseInt(heading.closest('.page,.phb').id?.replace(/^p/, ''));
|
const onPage = parseInt(heading.closest('.page,.phb').id?.replace(/^p/, ''));
|
||||||
@@ -47,6 +80,15 @@ const getTOC = ()=>{
|
|||||||
if(heading.tagName == 'H3') {
|
if(heading.tagName == 'H3') {
|
||||||
add3(headingText, onPage);
|
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){
|
if(g2.children.length){
|
||||||
_.each(g2.children, (g3, idx3)=>{
|
_.each(g2.children, (g3, idx3)=>{
|
||||||
if(g2.title !== null) {
|
if(g3.title !== null) {
|
||||||
r.push(` - [{{ ${g3.title}}}{{ ${g3.page}}}](#p${g3.page})`);
|
if(g2.title !== null) {
|
||||||
} 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})`);
|
} 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})`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -791,6 +791,9 @@
|
|||||||
// *****************************/
|
// *****************************/
|
||||||
|
|
||||||
// Default Exclusions
|
// Default Exclusions
|
||||||
|
h4,
|
||||||
|
h5,
|
||||||
|
h6,
|
||||||
.page:has(.frontCover),
|
.page:has(.frontCover),
|
||||||
.page:has(.backCover),
|
.page:has(.backCover),
|
||||||
.page:has(.insideCover),
|
.page:has(.insideCover),
|
||||||
@@ -799,6 +802,19 @@
|
|||||||
.noToC,
|
.noToC,
|
||||||
.toc { --TOC: exclude; }
|
.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 {
|
.page {
|
||||||
&:has(.toc)::after { display : none; }
|
&:has(.toc)::after { display : none; }
|
||||||
.toc {
|
.toc {
|
||||||
|
|||||||
Reference in New Issue
Block a user