book-source 0.3.16 → 0.3.18

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -41,6 +41,7 @@ function StructuredDocument() {
41
41
  this.metadata = null ;
42
42
  this.theme = null ;
43
43
  this.toc = null ;
44
+ this.tocList = null ;
44
45
  this.parts = [] ;
45
46
  //this.idList = new Set() ;
46
47
  }
@@ -58,7 +59,7 @@ StructuredDocument.prototype.render = function( renderer , special = null ) {
58
59
 
59
60
  switch ( special ) {
60
61
  case 'toc' :
61
- toRender = this.toc ? [ this.toc ] : [] ;
62
+ toRender = this.tocList ? [ this.tocList ] : [] ;
62
63
  break ;
63
64
  default :
64
65
  toRender = this.parts ;
@@ -98,6 +98,8 @@ exports.toc = ( structuredDocument , object , params , data ) => {
98
98
  let text = new documentParts.Text( StructuredDocument.getText( object ) ) ;
99
99
  link.parts.push( text ) ;
100
100
 
101
+ let simpleItem = { title: object.getText() , href: '#' + object.id , children: [] } ;
102
+
101
103
  if ( ! data.tocHeaderLevelStack.length ) {
102
104
  data.tocHeaderLevelStack.push( object.level ) ;
103
105
  }
@@ -112,18 +114,28 @@ exports.toc = ( structuredDocument , object , params , data ) => {
112
114
  }
113
115
 
114
116
  if ( object.level > lastHeaderLevel ) {
117
+ data.tocHeaderLevelStack.push( object.level ) ;
118
+
115
119
  let parentList = data.tocListStack[ lastListLevel ] ;
116
120
  let parentListItem = parentList.parts[ parentList.parts.length - 1 ] ;
117
121
  let currentList = new documentParts.List( object.level - 1 ) ;
118
- data.tocListStack.push( currentList ) ;
119
- data.tocHeaderLevelStack.push( object.level ) ;
120
122
  currentList.parts.push( item ) ;
123
+ data.tocListStack.push( currentList ) ;
121
124
  parentListItem.parts.push( currentList ) ;
125
+
126
+ let parentSimpleList = data.tocSimpleListStack[ lastListLevel ] ;
127
+ let parentSimpleItem = parentSimpleList[ parentSimpleList.length - 1 ] ;
128
+ let currentSimpleList = parentSimpleItem.children ;
129
+ currentSimpleList.push( simpleItem ) ;
130
+ data.tocSimpleListStack.push( currentSimpleList ) ;
122
131
  }
123
132
  else {
124
133
  // It's equal OR the doc is not well-formed and it's less, nevertheless, we just act as if it's equal
125
134
  let currentList = data.tocListStack[ lastListLevel ] ;
126
135
  currentList.parts.push( item ) ;
136
+
137
+ let currentSimpleList = data.tocSimpleListStack[ lastListLevel ] ;
138
+ currentSimpleList.push( simpleItem ) ;
127
139
  }
128
140
  } ;
129
141
 
@@ -136,12 +148,18 @@ exports.toc.init = ( structuredDocument , params , data ) => {
136
148
  function resetToc( data ) {
137
149
  data.tocList = new documentParts.List( 0 ) ;
138
150
  data.tocListStack = [ data.tocList ] ;
151
+
152
+ // Variant easier to manage for custom userland
153
+ data.tocSimpleList = [] ;
154
+ data.tocSimpleListStack = [ data.tocSimpleList ] ;
155
+
139
156
  data.tocHeaderLevelStack = [] ;
140
157
  data.tocEnded = false ;
141
158
  }
142
159
 
143
160
  exports.toc.finalize = ( structuredDocument , params , data ) => {
144
- structuredDocument.toc = data.tocList ;
161
+ structuredDocument.tocList = data.tocList ;
162
+ structuredDocument.toc = data.tocSimpleList ;
145
163
 
146
164
  for ( let tocObject of data.tocObjects ) {
147
165
  tocObject.parts.push( data.tocList ) ;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "book-source",
3
- "version": "0.3.16",
3
+ "version": "0.3.18",
4
4
  "description": "A lightweight markup language, inspired by Markdown.",
5
5
  "main": "lib/book-source.js",
6
6
  "directories": {