0
0
mirror of https://github.com/naturalcrit/homebrewery.git synced 2026-01-13 06:32:39 +00:00

Work on the Table of contents snippet

This commit is contained in:
Scott Tolksdorf
2017-03-19 17:26:55 -04:00
parent c647bdf5ee
commit 28a3f31caa
9 changed files with 242 additions and 44 deletions

View File

@@ -48,7 +48,7 @@ const getTOC = (pages) => {
}
module.exports = function(brew){
const pages = brew.split('\\page');
const TOC = getTOC(pages);
const markdown = _.reduce(TOC, (r, g1, idx1)=>{
r.push(`- **[${idx1 + 1} ${g1.title}](#p${g1.page})**`)

View File

@@ -6,7 +6,6 @@ const cx = require('classnames');
const SnippetGroup = React.createClass({
getDefaultProps: function() {
return {
brew : '',
name : '',
icon : 'fa-rocket',
snippets : [],

View File

@@ -1,5 +1,4 @@
///////////////////
.spell{
ul:first-of-type{
@@ -16,7 +15,7 @@
.monster{
.breakAvoid();
.pseudoBorder();
padding : 10px 5px;
padding : 10px 5px;
table{
color : @headerText;
}
@@ -86,7 +85,6 @@
border-image-width : 47px;
}
}
.footnote{
position : absolute;
right : 80px;
@@ -97,13 +95,46 @@
color : @gold;
text-align : right;
}
//*****************************
// * TABLE OF CONTENTS
// *****************************/
.toc{
.breakAvoid();
h1{
text-align : center;
}
li{
margin-bottom : 3px;
strong, em::after{
font-family : BookInsanity;
font-size : 13px;
font-style : normal;
font-weight : 500;
color : black;
}
em{
display : block;
overflow : hidden;
width : auto;
font-style : normal;
white-space : nowrap;
&:after{
content : " ..............................................................................................................";
}
}
strong{
float : right;
margin-left : 4px;
}
h3{
margin-top : 15px;
em{ color : @crimson; }
em::after{ display : none; }
}
h4{
margin-top : 10px;
em{ color : @crimson; }
}
}
a{
color : black;
text-decoration : none;
@@ -115,17 +146,7 @@
padding-left : 0;
list-style-type : none;
}
&>ul>li{
margin-bottom : 10px;
}
}
.wide{
column-span : all;
-webkit-column-span : all;
@@ -133,25 +154,25 @@
}
.oneColumn{
column-count : 1;
column-gap : 1cm;
// column-gap : 1cm;
}
.twoColumn{
column-count : 2;
column-gap : 1cm;
//column-fill: auto;
////column-gap : 1cm;
}
.threeColumn{
column-count : 3;
column-gap : 1cm;
//column-gap : 1cm;
}
.fourColumn{
column-count : 4;
column-gap : 1cm;
//column-gap : 1cm;
}
.columnSplit{
visibility : hidden;
-webkit-column-break-after : always;
break-after : always;
-moz-column-break-after : always;
-webkit-column-break-bfore : always;
break-before : column;
}
.brushed{
border-image-outset : 25px 17px;

View File

@@ -20,6 +20,7 @@
}
}
@crimson : #58180D;
@red : #9c2b1b;
@gold : #c9ad6a; //brown?
@green : #e0e5c1;

View File

@@ -3,9 +3,10 @@ const _ = require('lodash');
module.exports = _.merge(
require('./spell.snippet.js'),
require('./table.snippet.js'),
require('./classTable.snippet.js'),
require('./class.snippet.js'),
require('./note.snippet.js'),
require('./monster.snippet.js')
require('./monster.snippet.js'),
require('./toc.snippet.js')
//wide

View File

@@ -0,0 +1,112 @@
const _ = require('lodash');
const Store = require('homebrewery/brew.store.js');
const getTOC = (text) => {
const pages = text.split('\\page');
const add1 = (title, page)=>{
res.push({
title : title,
page : page + 1,
children : []
});
}
const add2 = (title, page)=>{
if(!_.last(res)) add1('', page);
_.last(res).children.push({
title : title,
page : page + 1,
children : []
});
}
const add3 = (title, page)=>{
if(!_.last(res)) add1('', page);
if(!_.last(_.last(res).children)) add2('', page);
_.last(_.last(res).children).children.push({
title : title,
page : page + 1,
children : []
});
}
let res = [];
_.each(pages, (page, pageNum)=>{
const lines = page.split('\n');
_.each(lines, (line) => {
if(_.startsWith(line, '# ')){
const title = line.replace('# ', '');
add1(title, pageNum)
}
if(_.startsWith(line, '## ')){
const title = line.replace('## ', '');
add2(title, pageNum);
}
if(_.startsWith(line, '### ')){
const title = line.replace('### ', '');
add3(title, pageNum);
}
})
});
return res;
}
module.exports = {
//TODO: TOC not perfect yet
toc : (text)=>{
text = text || Store.getBrewCode();
console.log(getTOC(text));
const TOC = getTOC(text)
const markdown = _.reduce(TOC, (r, g1, idx1)=>{
r.push(`- ### [**${g1.page}** *${g1.title}*](#p${g1.page})`)
if(g1.children.length){
_.each(g1.children, (g2, idx2) => {
r.push(` - #### [**${g2.page}** *${g2.title}*](#p${g2.page})`)
if(g2.children.length){
_.each(g2.children, (g3, idx3) => {
r.push(` - [**${g3.page}** *${g3.title}*](#p${g3.page})`)
});
}
});
}
return r;
}, []).join('\n');
return `{{toc
# Contents
${markdown}
}}`;
/*
- ### [**4** *Preface*](#p3)
- ### [**5** *Introduction*](#p3)
- [**5** *Worlds of Adventure*](#p5)
- [**6** *Using This Book*](#p5)
- [**6** *How to Play*](#p5)
- [**7** *Adventures*](#p5)
- ### [**5** *Introduction*](#p3)
- #### [**5** *Worlds of Adventure*](#p5)
- [**6** *Using This Book*](#p5)
- [**6** *How to Play*](#p5)
- #### [**7** *Adventures*](#p5)
}}
`;*/
}
}