mirror of
https://github.com/naturalcrit/homebrewery.git
synced 2026-01-05 18:52:38 +00:00
Table of Contents CSS and snippet
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
const _ = require('lodash');
|
||||
const dedent = require('dedent-tabs').default;
|
||||
|
||||
const getTOC = (pages)=>{
|
||||
const add1 = (title, page)=>{
|
||||
@@ -51,13 +52,13 @@ module.exports = function(brew){
|
||||
const pages = brew.text.split('\\page');
|
||||
const TOC = getTOC(pages);
|
||||
const markdown = _.reduce(TOC, (r, g1, idx1)=>{
|
||||
r.push(`- **[${idx1 + 1} ${g1.title}](#p${g1.page})**`);
|
||||
r.push(`\t\t- ### [{{ ${g1.title}}}{{ ${g1.page}}}](#p${g1.page})`);
|
||||
if(g1.children.length){
|
||||
_.each(g1.children, (g2, idx2)=>{
|
||||
r.push(` - [${idx1 + 1}.${idx2 + 1} ${g2.title}](#p${g2.page})`);
|
||||
r.push(`\t\t - #### [{{ ${g2.title}}}{{ ${g2.page}}}](#p${g2.page})`);
|
||||
if(g2.children.length){
|
||||
_.each(g2.children, (g3, idx3)=>{
|
||||
r.push(` - [${idx1 + 1}.${idx2 + 1}.${idx3 + 1} ${g3.title}](#p${g3.page})`);
|
||||
r.push(`\t\t - [{{ ${g3.title}}}{{ ${g3.page}}}](#p${g3.page})`);
|
||||
});
|
||||
}
|
||||
});
|
||||
@@ -65,8 +66,11 @@ module.exports = function(brew){
|
||||
return r;
|
||||
}, []).join('\n');
|
||||
|
||||
return `<div class='toc'>
|
||||
##### Table Of Contents
|
||||
return dedent`
|
||||
{{toc
|
||||
# Table Of Contents
|
||||
|
||||
${markdown}
|
||||
</div>\n`;
|
||||
}}
|
||||
\n`;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user