From 7ff6d9e82588ebe7d94d9b632de4650586255cde Mon Sep 17 00:00:00 2001 From: Trevor Buckner Date: Tue, 20 Jul 2021 15:40:32 -0400 Subject: [PATCH] Fix TOC generation for level 3 entries not inside level 2 --- .../snippets/tableOfContents.gen.js | 21 +++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/client/homebrew/editor/snippetbar/snippets/tableOfContents.gen.js b/client/homebrew/editor/snippetbar/snippets/tableOfContents.gen.js index e2a1221eb..c351ff1aa 100644 --- a/client/homebrew/editor/snippetbar/snippets/tableOfContents.gen.js +++ b/client/homebrew/editor/snippetbar/snippets/tableOfContents.gen.js @@ -10,7 +10,7 @@ const getTOC = (pages)=>{ }); }; const add2 = (title, page)=>{ - if(!_.last(res)) add1('', page); + if(!_.last(res)) add1(null, page); _.last(res).children.push({ title : title, page : page + 1, @@ -18,8 +18,8 @@ const getTOC = (pages)=>{ }); }; const add3 = (title, page)=>{ - if(!_.last(res)) add1('', page); - if(!_.last(_.last(res).children)) add2('', 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, @@ -52,13 +52,22 @@ module.exports = function(brew){ const pages = brew.text.split('\\page'); const TOC = getTOC(pages); 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){ _.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){ _.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})`); + } }); } });