mirror of
https://github.com/naturalcrit/homebrewery.git
synced 2026-01-18 10:02:49 +00:00
Fix TOC generation for level 3 entries not inside level 2
This commit is contained in:
@@ -10,7 +10,7 @@ const getTOC = (pages)=>{
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
const add2 = (title, page)=>{
|
const add2 = (title, page)=>{
|
||||||
if(!_.last(res)) add1('', page);
|
if(!_.last(res)) add1(null, page);
|
||||||
_.last(res).children.push({
|
_.last(res).children.push({
|
||||||
title : title,
|
title : title,
|
||||||
page : page + 1,
|
page : page + 1,
|
||||||
@@ -18,8 +18,8 @@ const getTOC = (pages)=>{
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
const add3 = (title, page)=>{
|
const add3 = (title, page)=>{
|
||||||
if(!_.last(res)) add1('', page);
|
if(!_.last(res)) add1(null, page);
|
||||||
if(!_.last(_.last(res).children)) add2('', page);
|
if(!_.last(_.last(res).children)) add2(null, page);
|
||||||
_.last(_.last(res).children).children.push({
|
_.last(_.last(res).children).children.push({
|
||||||
title : title,
|
title : title,
|
||||||
page : page + 1,
|
page : page + 1,
|
||||||
@@ -52,13 +52,22 @@ module.exports = function(brew){
|
|||||||
const pages = brew.text.split('\\page');
|
const pages = brew.text.split('\\page');
|
||||||
const TOC = getTOC(pages);
|
const TOC = getTOC(pages);
|
||||||
const markdown = _.reduce(TOC, (r, g1, idx1)=>{
|
const markdown = _.reduce(TOC, (r, g1, idx1)=>{
|
||||||
r.push(`\t\t- ### [{{ ${g1.title}}}{{ ${g1.page}}}](#p${g1.page})`);
|
if(g1.title !== null) {
|
||||||
|
r.push(`\t\t- ### [{{ ${g1.title}}}{{ ${g1.page}}}](#p${g1.page})`);
|
||||||
|
}
|
||||||
if(g1.children.length){
|
if(g1.children.length){
|
||||||
_.each(g1.children, (g2, idx2)=>{
|
_.each(g1.children, (g2, idx2)=>{
|
||||||
r.push(`\t\t - #### [{{ ${g2.title}}}{{ ${g2.page}}}](#p${g2.page})`);
|
if(g2.title !== null) {
|
||||||
|
r.push(`\t\t - #### [{{ ${g2.title}}}{{ ${g2.page}}}](#p${g2.page})`);
|
||||||
|
}
|
||||||
if(g2.children.length){
|
if(g2.children.length){
|
||||||
_.each(g2.children, (g3, idx3)=>{
|
_.each(g2.children, (g3, idx3)=>{
|
||||||
r.push(`\t\t - [{{ ${g3.title}}}{{ ${g3.page}}}](#p${g3.page})`);
|
if(g2.title !== null) {
|
||||||
|
r.push(`\t\t - [{{ ${g3.title}}}{{ ${g3.page}}}](#p${g3.page})`);
|
||||||
|
}
|
||||||
|
else { // Don't over-indent if no level-2 parent entry
|
||||||
|
r.push(`\t\t - [{{ ${g3.title}}}{{ ${g3.page}}}](#p${g3.page})`);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user