book-source 0.2.0 → 0.2.2
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.
- package/README.md +2 -2
- package/documentation.md +2 -2
- package/lib/StructuredDocument.js +123 -132
- package/lib/book-source.js +2 -0
- package/lib/documentParts.js +445 -0
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
|
|
2
2
|
# Book Source
|
|
3
3
|
|
|
4
|
-
|
|
4
|
+
Book Source is a Lightweight Markup Language similar to Markdown.
|
|
5
5
|
|
|
6
|
-
This
|
|
6
|
+
This is the parser, you may want to add a renderer, like the [Book Source HTML renderer](https://github.com/cronvel/book-source-html-renderer).
|
|
7
7
|
|
|
8
8
|
New renderers can easily be created.
|
|
9
9
|
|
package/documentation.md
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
|
|
2
2
|
# Book Source
|
|
3
3
|
|
|
4
|
-
|
|
4
|
+
Book Source is a Lightweight Markup Language similar to Markdown.
|
|
5
5
|
|
|
6
|
-
This
|
|
6
|
+
This is the parser, you may want to add a renderer, like the [Book Source HTML renderer](https://github.com/cronvel/book-source-html-renderer).
|
|
7
7
|
|
|
8
8
|
New renderers can easily be created.
|
|
9
9
|
|
|
@@ -28,10 +28,10 @@
|
|
|
28
28
|
|
|
29
29
|
|
|
30
30
|
|
|
31
|
+
const documentParts = require( './documentParts.js' ) ;
|
|
31
32
|
const Style = require( './Style.js' ) ;
|
|
32
33
|
const Theme = require( './Theme.js' ) ;
|
|
33
34
|
|
|
34
|
-
const emoji = require( 'string-kit/lib/emoji.js' ) ;
|
|
35
35
|
const inPlaceFilter = require( 'array-kit/lib/inPlaceFilter.js' ) ;
|
|
36
36
|
|
|
37
37
|
|
|
@@ -67,33 +67,33 @@ StructuredDocument.prototype.renderParts = function( renderer , parts , partStac
|
|
|
67
67
|
var str = '' , index = 0 ;
|
|
68
68
|
|
|
69
69
|
for ( let part of parts ) {
|
|
70
|
-
let
|
|
70
|
+
let partsStr = '' ;
|
|
71
71
|
|
|
72
|
-
if ( part.
|
|
72
|
+
if ( part.parts ) {
|
|
73
73
|
if ( renderer.group?.[ part.type ] ) {
|
|
74
|
-
// Some renderer have to group
|
|
74
|
+
// Some renderer have to group child parts an apply things to each group,
|
|
75
75
|
// E.g. HTML groups 'tableHeader' to produce <thead> and 'tableRow' to produce <tbody>
|
|
76
|
-
let groupList = this.groupByType( part.
|
|
76
|
+
let groupList = this.groupByType( part.parts , renderer.group[ part.type ] ) ;
|
|
77
77
|
//console.error( "groupList:" , groupList ) ;
|
|
78
78
|
|
|
79
79
|
for ( let group of groupList ) {
|
|
80
80
|
if ( renderer.group[ part.type ][ group.type ] ) {
|
|
81
81
|
partStack.push( part ) ;
|
|
82
|
-
let groupStr = this.renderParts( renderer , group.
|
|
82
|
+
let groupStr = this.renderParts( renderer , group.parts , partStack ) ;
|
|
83
83
|
partStack.pop() ;
|
|
84
|
-
|
|
84
|
+
partsStr += renderer.group[ part.type ][ group.type ]( part , groupStr , partStack ) ;
|
|
85
85
|
}
|
|
86
86
|
}
|
|
87
87
|
}
|
|
88
88
|
else {
|
|
89
89
|
partStack.push( part ) ;
|
|
90
|
-
|
|
90
|
+
partsStr = this.renderParts( renderer , part.parts , [ ... partStack , part ] ) ;
|
|
91
91
|
partStack.pop() ;
|
|
92
92
|
}
|
|
93
93
|
}
|
|
94
94
|
|
|
95
95
|
if ( renderer[ part.type ] ) {
|
|
96
|
-
str += renderer[ part.type ]( part ,
|
|
96
|
+
str += renderer[ part.type ]( part , partsStr , partStack , index ) ;
|
|
97
97
|
}
|
|
98
98
|
|
|
99
99
|
index ++ ;
|
|
@@ -112,13 +112,13 @@ StructuredDocument.prototype.groupByType = function( parts , rendererGroup ) {
|
|
|
112
112
|
if ( ! group ) {
|
|
113
113
|
group = groupMap[ part.type ] = {
|
|
114
114
|
type: part.type ,
|
|
115
|
-
|
|
115
|
+
parts: [] ,
|
|
116
116
|
order: + rendererGroup[ part.type ]?.order || 0
|
|
117
117
|
} ;
|
|
118
118
|
groupList.push( group ) ;
|
|
119
119
|
}
|
|
120
120
|
|
|
121
|
-
group.
|
|
121
|
+
group.parts.push( part ) ;
|
|
122
122
|
}
|
|
123
123
|
|
|
124
124
|
groupList.sort( ( a , b ) => a.order - b.order ) ;
|
|
@@ -137,7 +137,7 @@ StructuredDocument.prototype.autoTitle = function() {
|
|
|
137
137
|
|
|
138
138
|
if ( ! header ) { return ; }
|
|
139
139
|
|
|
140
|
-
str = this.getText( header.
|
|
140
|
+
str = this.getText( header.parts ) ;
|
|
141
141
|
if ( str ) { this.title = str ; }
|
|
142
142
|
} ;
|
|
143
143
|
|
|
@@ -148,7 +148,7 @@ StructuredDocument.prototype.getText = function( parts ) { //= this.parts ) {
|
|
|
148
148
|
|
|
149
149
|
for ( let part of parts ) {
|
|
150
150
|
if ( part.text ) { str += part.text ; }
|
|
151
|
-
else if ( part.
|
|
151
|
+
else if ( part.parts?.length ) { str += this.getText( part.parts ) ; }
|
|
152
152
|
}
|
|
153
153
|
|
|
154
154
|
return str ;
|
|
@@ -232,7 +232,7 @@ function parseBlock( str , ctx ) {
|
|
|
232
232
|
}
|
|
233
233
|
|
|
234
234
|
if ( indentType === QUOTE_INDENT ) {
|
|
235
|
-
ctx.parts.push(
|
|
235
|
+
ctx.parts.push( new documentParts.Quote( indentSpaces ) ) ;
|
|
236
236
|
stack( ctx ) ;
|
|
237
237
|
}
|
|
238
238
|
else if ( indentType <= 0 ) {
|
|
@@ -542,13 +542,13 @@ const PARAGRAPH_END_PARAMS = {
|
|
|
542
542
|
|
|
543
543
|
function parseParagraph( str , ctx ) {
|
|
544
544
|
//console.error( "parseParagraph in:" , ctx.i , str.slice( ctx.i ) ) ;
|
|
545
|
-
ctx.parts.push(
|
|
545
|
+
ctx.parts.push( new documentParts.Paragraph() ) ;
|
|
546
546
|
|
|
547
547
|
var blockEnd = detectBlockEnd( str , ctx.i , ctx.parent?.indent , PARAGRAPH_END_PARAMS ) ;
|
|
548
548
|
//console.error( "blockEnd:" , blockEnd ) ;
|
|
549
549
|
parseInlineChildren( str , ctx , blockEnd ) ;
|
|
550
550
|
|
|
551
|
-
//console.error( "
|
|
551
|
+
//console.error( "parts:" , parts ) ;
|
|
552
552
|
//console.error( "parseParagraph out:" , ctx.i , str.slice( ctx.i ) ) ;
|
|
553
553
|
}
|
|
554
554
|
|
|
@@ -567,7 +567,7 @@ function parseHeader( str , ctx ) {
|
|
|
567
567
|
|
|
568
568
|
ctx.i += streak ;
|
|
569
569
|
if ( str[ ctx.i ] === ' ' ) { ctx.i ++ ; }
|
|
570
|
-
ctx.parts.push(
|
|
570
|
+
ctx.parts.push( new documentParts.Header( streak ) ) ;
|
|
571
571
|
|
|
572
572
|
var blockEnd = detectBlockEnd( str , ctx.i , ctx.parent?.indent , HEADER_END_PARAMS ) ;
|
|
573
573
|
parseInlineChildren( str , ctx , blockEnd ) ;
|
|
@@ -584,7 +584,7 @@ const CITE_END_PARAMS = {
|
|
|
584
584
|
|
|
585
585
|
function parseCite( str , ctx ) {
|
|
586
586
|
ctx.i += 3 ;
|
|
587
|
-
ctx.parts.push(
|
|
587
|
+
ctx.parts.push( new documentParts.Cite() ) ;
|
|
588
588
|
|
|
589
589
|
var blockEnd = detectBlockEnd( str , ctx.i , ctx.parent?.indent , CITE_END_PARAMS ) ;
|
|
590
590
|
parseInlineChildren( str , ctx , blockEnd ) ;
|
|
@@ -606,12 +606,12 @@ function parseListItem( str , ctx , indent ) {
|
|
|
606
606
|
var lastPart = ctx.parts[ ctx.parts.length - 1 ] ;
|
|
607
607
|
|
|
608
608
|
if ( ! lastPart || lastPart.type !== 'list' ) {
|
|
609
|
-
ctx.parts.push(
|
|
609
|
+
ctx.parts.push( new documentParts.List( indent ) ) ;
|
|
610
610
|
}
|
|
611
611
|
|
|
612
612
|
stack( ctx ) ;
|
|
613
613
|
|
|
614
|
-
ctx.parts.push(
|
|
614
|
+
ctx.parts.push( new documentParts.ListItem( indent ) ) ;
|
|
615
615
|
|
|
616
616
|
var blockEnd = detectBlockEnd( str , ctx.i , ctx.parent?.indent , LIST_ITEM_END_PARAMS ) ;
|
|
617
617
|
parseInlineChildren( str , ctx , blockEnd ) ;
|
|
@@ -629,12 +629,12 @@ function parseOrderedListItem( str , ctx , indent ) {
|
|
|
629
629
|
var lastPart = ctx.parts[ ctx.parts.length - 1 ] ;
|
|
630
630
|
|
|
631
631
|
if ( ! lastPart || lastPart.type !== 'orderedList' ) {
|
|
632
|
-
ctx.parts.push(
|
|
632
|
+
ctx.parts.push( new documentParts.OrderedList( indent ) ) ;
|
|
633
633
|
}
|
|
634
634
|
|
|
635
635
|
stack( ctx ) ;
|
|
636
636
|
|
|
637
|
-
ctx.parts.push(
|
|
637
|
+
ctx.parts.push( new documentParts.OrderedListItem( indent , order ) ) ;
|
|
638
638
|
|
|
639
639
|
var blockEnd = detectBlockEnd( str , ctx.i , ctx.parent?.indent , LIST_ITEM_END_PARAMS ) ;
|
|
640
640
|
parseInlineChildren( str , ctx , blockEnd ) ;
|
|
@@ -695,7 +695,7 @@ function parseMedia( str , ctx , float = null ) {
|
|
|
695
695
|
|
|
696
696
|
|
|
697
697
|
function parseHorizontalRule( str , ctx ) {
|
|
698
|
-
var
|
|
698
|
+
var clearFloat = false ,
|
|
699
699
|
streak = countStreak( str , ctx.i , '-' ) ;
|
|
700
700
|
|
|
701
701
|
if (
|
|
@@ -705,10 +705,10 @@ function parseHorizontalRule( str , ctx ) {
|
|
|
705
705
|
&& str[ ctx.i + streak + 3 ] === '-'
|
|
706
706
|
&& str[ ctx.i + streak + 4 ] === '-'
|
|
707
707
|
) {
|
|
708
|
-
|
|
708
|
+
clearFloat = true ;
|
|
709
709
|
}
|
|
710
710
|
|
|
711
|
-
ctx.parts.push(
|
|
711
|
+
ctx.parts.push( new documentParts.HorizontalRule( clearFloat ) ) ;
|
|
712
712
|
ctx.i = searchEndOfLine( str , ctx.i ) + 1 ;
|
|
713
713
|
}
|
|
714
714
|
|
|
@@ -718,7 +718,7 @@ function parseClearFloat( str , ctx ) {
|
|
|
718
718
|
var streak = countStreak( str , ctx.i + 1 , '-' ) ;
|
|
719
719
|
|
|
720
720
|
if ( str[ ctx.i + 1 + streak ] === '>' ) {
|
|
721
|
-
ctx.parts.push(
|
|
721
|
+
ctx.parts.push( new documentParts.ClearFloat() ) ;
|
|
722
722
|
ctx.i = searchEndOfLine( str , ctx.i ) + 1 ;
|
|
723
723
|
}
|
|
724
724
|
else {
|
|
@@ -740,12 +740,10 @@ function parseCodeBlock( str , ctx ) {
|
|
|
740
740
|
return parseParagraph( str , ctx ) ;
|
|
741
741
|
}
|
|
742
742
|
|
|
743
|
-
var [ contentEnd , blockEnd ] = ends
|
|
743
|
+
var [ contentEnd , blockEnd ] = ends ,
|
|
744
|
+
text = str.slice( contentStart , contentEnd - 1 ) ; // We strip the last newline
|
|
744
745
|
|
|
745
|
-
|
|
746
|
-
if ( lang ) { params.lang = lang ; }
|
|
747
|
-
params.text = str.slice( contentStart , contentEnd - 1 ) ; // We strip the last newline
|
|
748
|
-
ctx.parts.push( params ) ;
|
|
746
|
+
ctx.parts.push( new documentParts.CodeBlock( text , lang ) ) ;
|
|
749
747
|
ctx.i = blockEnd ;
|
|
750
748
|
}
|
|
751
749
|
|
|
@@ -778,10 +776,7 @@ function parseAnchor( str , ctx ) {
|
|
|
778
776
|
var end = searchCloser( str , ctx.i + 2 , '(' , ')' , true ) ;
|
|
779
777
|
if ( end < 0 ) { return parseParagraph( str , ctx ) ; }
|
|
780
778
|
|
|
781
|
-
ctx.parts.push(
|
|
782
|
-
type: 'anchor' ,
|
|
783
|
-
href: str.slice( ctx.i + 2 , end )
|
|
784
|
-
} ) ;
|
|
779
|
+
ctx.parts.push( new documentParts.Anchor( str.slice( ctx.i + 2 , end ) ) ) ;
|
|
785
780
|
|
|
786
781
|
ctx.i = end + 1 ;
|
|
787
782
|
}
|
|
@@ -802,7 +797,7 @@ function parseTableCaption( str , ctx ) {
|
|
|
802
797
|
var table = ctx.parts[ ctx.parts.length - 1 ] ;
|
|
803
798
|
|
|
804
799
|
if ( ! table || table.type !== 'table' || ctx.lastLineWasEmpty ) {
|
|
805
|
-
table =
|
|
800
|
+
table = new documentParts.Table() ;
|
|
806
801
|
ctx.parts.push( table ) ;
|
|
807
802
|
}
|
|
808
803
|
|
|
@@ -813,7 +808,7 @@ function parseTableCaption( str , ctx ) {
|
|
|
813
808
|
tableCaption = lastRow ;
|
|
814
809
|
|
|
815
810
|
if ( ! lastRow || lastRow.type !== 'tableCaption' ) {
|
|
816
|
-
tableCaption =
|
|
811
|
+
tableCaption = new documentParts.TableCaption() ;
|
|
817
812
|
ctx.parts.push( tableCaption ) ;
|
|
818
813
|
}
|
|
819
814
|
|
|
@@ -842,7 +837,7 @@ function parseTableRow( str , ctx ) {
|
|
|
842
837
|
mergeMode = false ;
|
|
843
838
|
|
|
844
839
|
if ( ! table || table.type !== 'table' || ctx.lastLineWasEmpty ) {
|
|
845
|
-
table =
|
|
840
|
+
table = new documentParts.Table() ;
|
|
846
841
|
ctx.parts.push( table ) ;
|
|
847
842
|
}
|
|
848
843
|
|
|
@@ -854,7 +849,7 @@ function parseTableRow( str , ctx ) {
|
|
|
854
849
|
tableRow = lastRow ;
|
|
855
850
|
|
|
856
851
|
if ( ! lastRow || lastRow.type !== 'tableRow' ) {
|
|
857
|
-
tableRow =
|
|
852
|
+
tableRow = new documentParts.TableRow() ;
|
|
858
853
|
ctx.parts.push( tableRow ) ;
|
|
859
854
|
}
|
|
860
855
|
else {
|
|
@@ -862,7 +857,7 @@ function parseTableRow( str , ctx ) {
|
|
|
862
857
|
}
|
|
863
858
|
}
|
|
864
859
|
else {
|
|
865
|
-
tableRow =
|
|
860
|
+
tableRow = new documentParts.TableRow() ;
|
|
866
861
|
ctx.parts.push( tableRow ) ;
|
|
867
862
|
}
|
|
868
863
|
|
|
@@ -896,7 +891,7 @@ function parseTableRow( str , ctx ) {
|
|
|
896
891
|
firstSpace = searchNext( str , currentBar + 1 , nextBar , ' ' ) ;
|
|
897
892
|
}
|
|
898
893
|
|
|
899
|
-
let tableCell =
|
|
894
|
+
let tableCell = new documentParts.TableCell() ;
|
|
900
895
|
|
|
901
896
|
// The '|' bar position helps for column span calculation
|
|
902
897
|
// sx = Start X, the x position of the left bar
|
|
@@ -945,7 +940,7 @@ function parseTableMultilineRow( str , ctx , lastCharOfLine , table , tableRow )
|
|
|
945
940
|
|
|
946
941
|
if ( str[ nextBar + 1 ] === '|' ) { columnSeparator = true ; }
|
|
947
942
|
|
|
948
|
-
tableCell = tableRow.
|
|
943
|
+
tableCell = tableRow.parts[ columnIndex ] ;
|
|
949
944
|
|
|
950
945
|
if ( tableCell ) {
|
|
951
946
|
ctx.i = firstSpace + 1 ;
|
|
@@ -969,7 +964,7 @@ function parseTableRowSeparator( str , ctx , thick = false ) {
|
|
|
969
964
|
table = ctx.parts[ ctx.parts.length - 1 ] ;
|
|
970
965
|
|
|
971
966
|
if ( ! table || table.type !== 'table' || ctx.lastLineWasEmpty ) {
|
|
972
|
-
table =
|
|
967
|
+
table = new documentParts.Table() ;
|
|
973
968
|
ctx.parts.push( table ) ;
|
|
974
969
|
}
|
|
975
970
|
|
|
@@ -983,8 +978,8 @@ function parseTableRowSeparator( str , ctx , thick = false ) {
|
|
|
983
978
|
if ( ! table.hasRowSeparator ) {
|
|
984
979
|
table.multilineRowMode = true ;
|
|
985
980
|
|
|
986
|
-
for ( let index = 0 ; index < table.
|
|
987
|
-
let child = table.
|
|
981
|
+
for ( let index = 0 ; index < table.parts.length ; index ++ ) {
|
|
982
|
+
let child = table.parts[ index ] ;
|
|
988
983
|
|
|
989
984
|
if ( child.type === 'tableRow' ) {
|
|
990
985
|
if ( ! tableRow ) {
|
|
@@ -993,22 +988,22 @@ function parseTableRowSeparator( str , ctx , thick = false ) {
|
|
|
993
988
|
else {
|
|
994
989
|
// All subsequent tableRows, are merged into the first tableRow
|
|
995
990
|
|
|
996
|
-
if ( child.
|
|
997
|
-
for ( columnIndex = 0 ; columnIndex < child.
|
|
998
|
-
let child2 = child.
|
|
991
|
+
if ( child.parts ) {
|
|
992
|
+
for ( columnIndex = 0 ; columnIndex < child.parts.length ; columnIndex ++ ) {
|
|
993
|
+
let child2 = child.parts[ columnIndex ] ;
|
|
999
994
|
if ( child2.type === 'tableCell' || child2.type === 'tableHeadCell' ) {
|
|
1000
|
-
if ( tableRow.
|
|
995
|
+
if ( tableRow.parts[ columnIndex ] ) {
|
|
1001
996
|
// Merge the cells
|
|
1002
|
-
mergeInlineParts( tableRow.
|
|
997
|
+
mergeInlineParts( tableRow.parts[ columnIndex ].parts , child2.parts ) ;
|
|
1003
998
|
}
|
|
1004
999
|
else {
|
|
1005
|
-
tableRow.
|
|
1000
|
+
tableRow.parts[ columnIndex ] = child2 ;
|
|
1006
1001
|
}
|
|
1007
1002
|
}
|
|
1008
1003
|
}
|
|
1009
1004
|
}
|
|
1010
1005
|
|
|
1011
|
-
table.
|
|
1006
|
+
table.parts.splice( index , 1 ) ;
|
|
1012
1007
|
index -- ;
|
|
1013
1008
|
}
|
|
1014
1009
|
}
|
|
@@ -1150,19 +1145,24 @@ function parseTableHeadRowSeparator( str , ctx , thick , lastCharOfLine ) {
|
|
|
1150
1145
|
// Should come AFTER, because it needs column info
|
|
1151
1146
|
// Fix previous table row as table head row: turn all existing tableRow into tableHeadRow
|
|
1152
1147
|
|
|
1153
|
-
for ( let index = 0 ; index < table.
|
|
1154
|
-
let child = table.
|
|
1148
|
+
for ( let index = 0 ; index < table.parts.length ; index ++ ) {
|
|
1149
|
+
let child = table.parts[ index ] ;
|
|
1155
1150
|
|
|
1156
1151
|
if ( child.type === 'tableRow' ) {
|
|
1157
1152
|
if ( ! tableHeadRow ) {
|
|
1158
1153
|
// This is the first tableRow, turn it into a a tableHeadRow
|
|
1159
|
-
child.type = 'tableHeadRow' ;
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
1154
|
+
//child.type = 'tableHeadRow' ;
|
|
1155
|
+
table.parts[ index ] = child = child.toHead() ;
|
|
1156
|
+
|
|
1157
|
+
if ( child.parts ) {
|
|
1158
|
+
for ( columnIndex = 0 ; columnIndex < child.parts.length ; columnIndex ++ ) {
|
|
1159
|
+
let child2 = child.parts[ columnIndex ] ;
|
|
1160
|
+
if ( child2.type === 'tableCell' ) {
|
|
1161
|
+
//child2.type = 'tableHeadCell' ;
|
|
1162
|
+
child.parts[ columnIndex ] = child2 = child2.toHead() ;
|
|
1163
|
+
child2.isColumnHead = true ;
|
|
1164
|
+
}
|
|
1165
|
+
else if ( child2.type === 'tableHeadCell' ) {
|
|
1166
1166
|
child2.isColumnHead = true ;
|
|
1167
1167
|
}
|
|
1168
1168
|
}
|
|
@@ -1174,24 +1174,35 @@ function parseTableHeadRowSeparator( str , ctx , thick , lastCharOfLine ) {
|
|
|
1174
1174
|
else {
|
|
1175
1175
|
// All subsequent tableRows, are merged into the first tableHeadRow created
|
|
1176
1176
|
|
|
1177
|
-
if ( child.
|
|
1178
|
-
for ( columnIndex = 0 ; columnIndex < child.
|
|
1179
|
-
let child2 = child.
|
|
1180
|
-
if ( child2.type === 'tableCell'
|
|
1181
|
-
if ( tableHeadRow.
|
|
1177
|
+
if ( child.parts ) {
|
|
1178
|
+
for ( columnIndex = 0 ; columnIndex < child.parts.length ; columnIndex ++ ) {
|
|
1179
|
+
let child2 = child.parts[ columnIndex ] ;
|
|
1180
|
+
if ( child2.type === 'tableCell' ) {
|
|
1181
|
+
if ( tableHeadRow.parts[ columnIndex ] ) {
|
|
1182
|
+
// Merge the cells
|
|
1183
|
+
mergeInlineParts( tableHeadRow.parts[ columnIndex ].parts , child2.parts ) ;
|
|
1184
|
+
}
|
|
1185
|
+
else {
|
|
1186
|
+
//child2.type = 'tableHeadCell' ;
|
|
1187
|
+
child.parts[ columnIndex ] = child2 = child2.toHead() ;
|
|
1188
|
+
child2.isColumnHead = true ;
|
|
1189
|
+
tableHeadRow.parts[ columnIndex ] = child2 ;
|
|
1190
|
+
}
|
|
1191
|
+
}
|
|
1192
|
+
else if ( child2.type === 'tableHeadCell' ) {
|
|
1193
|
+
if ( tableHeadRow.parts[ columnIndex ] ) {
|
|
1182
1194
|
// Merge the cells
|
|
1183
|
-
mergeInlineParts( tableHeadRow.
|
|
1195
|
+
mergeInlineParts( tableHeadRow.parts[ columnIndex ].parts , child2.parts ) ;
|
|
1184
1196
|
}
|
|
1185
1197
|
else {
|
|
1186
|
-
child2.type = 'tableHeadCell' ;
|
|
1187
1198
|
child2.isColumnHead = true ;
|
|
1188
|
-
tableHeadRow.
|
|
1199
|
+
tableHeadRow.parts[ columnIndex ] = child2 ;
|
|
1189
1200
|
}
|
|
1190
1201
|
}
|
|
1191
1202
|
}
|
|
1192
1203
|
}
|
|
1193
1204
|
|
|
1194
|
-
table.
|
|
1205
|
+
table.parts.splice( index , 1 ) ;
|
|
1195
1206
|
index -- ;
|
|
1196
1207
|
}
|
|
1197
1208
|
}
|
|
@@ -1210,11 +1221,11 @@ function parseTableHeadRowSeparator( str , ctx , thick , lastCharOfLine ) {
|
|
|
1210
1221
|
function computeIndexColumnSpan( ctx , table , tableRow ) {
|
|
1211
1222
|
var tableCell , cellIndex , column , columnIndex , columnSpan ,
|
|
1212
1223
|
columns = table.columns ,
|
|
1213
|
-
extraSpan = columns ? columns.length - tableRow.
|
|
1224
|
+
extraSpan = columns ? columns.length - tableRow.parts.length : 0 ;
|
|
1214
1225
|
|
|
1215
1226
|
|
|
1216
|
-
for ( cellIndex = columnIndex = 0 ; cellIndex < tableRow.
|
|
1217
|
-
tableCell = tableRow.
|
|
1227
|
+
for ( cellIndex = columnIndex = 0 ; cellIndex < tableRow.parts.length ; cellIndex ++ , columnIndex ++ ) {
|
|
1228
|
+
tableCell = tableRow.parts[ cellIndex ] ;
|
|
1218
1229
|
tableCell.column = columnIndex ;
|
|
1219
1230
|
columnSpan = 1 ;
|
|
1220
1231
|
|
|
@@ -1223,7 +1234,11 @@ function computeIndexColumnSpan( ctx , table , tableRow ) {
|
|
|
1223
1234
|
|
|
1224
1235
|
if ( column ) {
|
|
1225
1236
|
if ( column.headColumn ) {
|
|
1226
|
-
tableCell.type
|
|
1237
|
+
if ( tableCell.type === 'tableCell' ) {
|
|
1238
|
+
//tableCell.type = 'tableHeadCell' ;
|
|
1239
|
+
tableRow.parts[ cellIndex ] = tableCell = tableCell.toHead() ;
|
|
1240
|
+
}
|
|
1241
|
+
|
|
1227
1242
|
tableCell.isRowHead = true ;
|
|
1228
1243
|
}
|
|
1229
1244
|
}
|
|
@@ -1302,11 +1317,11 @@ function parseInline( str , ctx , blockEnd , trim = false ) {
|
|
|
1302
1317
|
}
|
|
1303
1318
|
else if ( char === '*' && ! WHITE_SPACES.has( str[ ctx.i + 1 ] ) ) {
|
|
1304
1319
|
addInlineTextChunk( str , ctx ) ;
|
|
1305
|
-
|
|
1320
|
+
parseEmphasisText( str , ctx , scanEnd ) ;
|
|
1306
1321
|
}
|
|
1307
1322
|
else if ( char === '_' && ! WHITE_SPACES.has( str[ ctx.i + 1 ] ) ) {
|
|
1308
1323
|
addInlineTextChunk( str , ctx ) ;
|
|
1309
|
-
|
|
1324
|
+
parseDecoratedText( str , ctx , scanEnd ) ;
|
|
1310
1325
|
}
|
|
1311
1326
|
else if ( char === '`' ) {
|
|
1312
1327
|
addInlineTextChunk( str , ctx ) ;
|
|
@@ -1347,10 +1362,7 @@ function addInlineTextChunk( str , ctx , forcedChunk = null ) {
|
|
|
1347
1362
|
lastPart.text += chunk ;
|
|
1348
1363
|
}
|
|
1349
1364
|
else {
|
|
1350
|
-
ctx.parts.push(
|
|
1351
|
-
type: 'text' ,
|
|
1352
|
-
text: chunk
|
|
1353
|
-
} ) ;
|
|
1365
|
+
ctx.parts.push( new documentParts.Text( chunk ) ) ;
|
|
1354
1366
|
}
|
|
1355
1367
|
}
|
|
1356
1368
|
|
|
@@ -1408,7 +1420,7 @@ function parseEscape( str , ctx ) {
|
|
|
1408
1420
|
|
|
1409
1421
|
|
|
1410
1422
|
|
|
1411
|
-
function
|
|
1423
|
+
function parseEmphasisText( str , ctx , blockEnd ) {
|
|
1412
1424
|
//console.error( "parseStyledText()" ) ;
|
|
1413
1425
|
var streak = countStreak( str , ctx.i , '*' ) ;
|
|
1414
1426
|
if ( streak > 3 ) { return ; }
|
|
@@ -1417,14 +1429,14 @@ function parseEmphasis( str , ctx , blockEnd ) {
|
|
|
1417
1429
|
|
|
1418
1430
|
var text = str.slice( ctx.i + streak , end + 1 - streak ) ;
|
|
1419
1431
|
|
|
1420
|
-
ctx.parts.push(
|
|
1432
|
+
ctx.parts.push( new documentParts.EmphasisText( text , streak ) ) ;
|
|
1421
1433
|
ctx.i = end ;
|
|
1422
1434
|
ctx.iStartOfInlineChunk = ctx.i + 1 ;
|
|
1423
1435
|
}
|
|
1424
1436
|
|
|
1425
1437
|
|
|
1426
1438
|
|
|
1427
|
-
function
|
|
1439
|
+
function parseDecoratedText( str , ctx , blockEnd ) {
|
|
1428
1440
|
//console.error( "parseStyledText()" ) ;
|
|
1429
1441
|
var streak = countStreak( str , ctx.i , '_' ) ;
|
|
1430
1442
|
if ( streak > 2 ) { return ; }
|
|
@@ -1433,9 +1445,7 @@ function parseDecoration( str , ctx , blockEnd ) {
|
|
|
1433
1445
|
|
|
1434
1446
|
var text = str.slice( ctx.i + streak , end + 1 - streak ) ;
|
|
1435
1447
|
|
|
1436
|
-
ctx.parts.push(
|
|
1437
|
-
type: 'decoration' , underline: true , level: streak , text
|
|
1438
|
-
} ) ;
|
|
1448
|
+
ctx.parts.push( new documentParts.DecoratedText( text , streak ) ) ;
|
|
1439
1449
|
ctx.i = end ;
|
|
1440
1450
|
ctx.iStartOfInlineChunk = ctx.i + 1 ;
|
|
1441
1451
|
}
|
|
@@ -1458,7 +1468,7 @@ function parseCode( str , ctx , blockEnd ) {
|
|
|
1458
1468
|
|
|
1459
1469
|
var text = str.slice( sliceStart , sliceEnd ) ;
|
|
1460
1470
|
|
|
1461
|
-
ctx.parts.push(
|
|
1471
|
+
ctx.parts.push( new documentParts.Code( text ) ) ;
|
|
1462
1472
|
ctx.i = end ;
|
|
1463
1473
|
ctx.iStartOfInlineChunk = ctx.i + 1 ;
|
|
1464
1474
|
}
|
|
@@ -1480,18 +1490,15 @@ function parseStyledText( str , ctx , blockEnd ) {
|
|
|
1480
1490
|
var data = parseDataMark( str , ctx , STYLE_DATA_MARK , blockEnd ) ;
|
|
1481
1491
|
if ( ! data ) { return ; }
|
|
1482
1492
|
|
|
1483
|
-
var
|
|
1484
|
-
|
|
1485
|
-
|
|
1486
|
-
if ( data.text?.[ 0 ] ) { params.title = data.text[ 0 ] ; }
|
|
1493
|
+
var href = data.href?.[ 0 ] ,
|
|
1494
|
+
style = data.style?.[ 0 ] ,
|
|
1495
|
+
title = data.text?.[ 0 ] ;
|
|
1487
1496
|
|
|
1488
|
-
if (
|
|
1489
|
-
|
|
1490
|
-
ctx.parts.push( params ) ;
|
|
1497
|
+
if ( href ) {
|
|
1498
|
+
ctx.parts.push( new documentParts.Link( text , href , style , title ) ) ;
|
|
1491
1499
|
}
|
|
1492
|
-
else if (
|
|
1493
|
-
|
|
1494
|
-
ctx.parts.push( params ) ;
|
|
1500
|
+
else if ( style || title ) {
|
|
1501
|
+
ctx.parts.push( new documentParts.StyledText( text , style , title ) ) ;
|
|
1495
1502
|
}
|
|
1496
1503
|
}
|
|
1497
1504
|
|
|
@@ -1513,29 +1520,13 @@ function parseImage( str , ctx , blockEnd ) {
|
|
|
1513
1520
|
var data = parseDataMark( str , ctx , IMAGE_DATA_MARK , blockEnd ) ;
|
|
1514
1521
|
if ( ! data ) { return ; }
|
|
1515
1522
|
|
|
1516
|
-
var
|
|
1517
|
-
if ( data.href?.[ 0 ] ) { params.href = data.href[ 0 ] ; }
|
|
1523
|
+
var href = data.href?.[ 0 ] ;
|
|
1518
1524
|
|
|
1519
|
-
if (
|
|
1520
|
-
|
|
1521
|
-
params.altText = text ;
|
|
1522
|
-
if ( data.text?.[ 0 ] ) { params.title = data.text[ 0 ] ; }
|
|
1523
|
-
ctx.parts.push( params ) ;
|
|
1525
|
+
if ( href ) {
|
|
1526
|
+
ctx.parts.push( new documentParts.Image( href , text , data.text?.[ 0 ] ) ) ;
|
|
1524
1527
|
}
|
|
1525
1528
|
else {
|
|
1526
|
-
|
|
1527
|
-
params.code = text ;
|
|
1528
|
-
let emojiChar = emoji.get( text ) ;
|
|
1529
|
-
if ( emojiChar ) { params.emoji = emojiChar ; }
|
|
1530
|
-
|
|
1531
|
-
if ( data.text?.[ 0 ] ) { params.altText = data.text[ 0 ] ; }
|
|
1532
|
-
if ( data.text?.[ 1 ] ) { params.title = data.text[ 1 ] ; }
|
|
1533
|
-
|
|
1534
|
-
if ( emojiChar && ! params.altText ) {
|
|
1535
|
-
params.altText = emoji.getCanonicalName( emojiChar ) ;
|
|
1536
|
-
}
|
|
1537
|
-
|
|
1538
|
-
ctx.parts.push( params ) ;
|
|
1529
|
+
ctx.parts.push( new documentParts.Pictogram( text , data.text?.[ 0 ] , data.text?.[ 1 ] ) ) ;
|
|
1539
1530
|
}
|
|
1540
1531
|
}
|
|
1541
1532
|
|
|
@@ -1597,7 +1588,7 @@ function postProcessTableRowSpan( table ) {
|
|
|
1597
1588
|
var tableRow , tableCell , masterCell , lastRow , lastContinueRowSpan ;
|
|
1598
1589
|
|
|
1599
1590
|
// First pass: merge cells
|
|
1600
|
-
for ( tableRow of table.
|
|
1591
|
+
for ( tableRow of table.parts ) {
|
|
1601
1592
|
if ( tableRow.type !== 'tableRow' ) { continue ; }
|
|
1602
1593
|
|
|
1603
1594
|
if ( lastContinueRowSpan ) {
|
|
@@ -1606,7 +1597,7 @@ function postProcessTableRowSpan( table ) {
|
|
|
1606
1597
|
masterCell = searchColumn( lastRow , columnIndex ) ;
|
|
1607
1598
|
if ( tableCell && masterCell ) {
|
|
1608
1599
|
if ( masterCell.masterCell ) { masterCell = masterCell.masterCell ; }
|
|
1609
|
-
mergeInlineParts( masterCell.
|
|
1600
|
+
mergeInlineParts( masterCell.parts , tableCell.parts ) ;
|
|
1610
1601
|
masterCell.rowSpan = ( masterCell.rowSpan || 1 ) + 1 ;
|
|
1611
1602
|
tableCell.masterCell = masterCell ;
|
|
1612
1603
|
}
|
|
@@ -1618,9 +1609,9 @@ function postProcessTableRowSpan( table ) {
|
|
|
1618
1609
|
}
|
|
1619
1610
|
|
|
1620
1611
|
// Second pass: remove dead cells
|
|
1621
|
-
for ( tableRow of table.
|
|
1612
|
+
for ( tableRow of table.parts ) {
|
|
1622
1613
|
if ( tableRow.type !== 'tableRow' ) { continue ; }
|
|
1623
|
-
inPlaceFilter( tableRow.
|
|
1614
|
+
inPlaceFilter( tableRow.parts , tableCell_ => ! tableCell_.masterCell ) ;
|
|
1624
1615
|
}
|
|
1625
1616
|
}
|
|
1626
1617
|
|
|
@@ -1658,7 +1649,7 @@ function mergeInlineParts( parts , extraParts ) {
|
|
|
1658
1649
|
}
|
|
1659
1650
|
else {
|
|
1660
1651
|
// Add an additional joint part
|
|
1661
|
-
parts.push(
|
|
1652
|
+
parts.push( new documentParts.Text( ' ' ) ) ;
|
|
1662
1653
|
}
|
|
1663
1654
|
}
|
|
1664
1655
|
|
|
@@ -1891,11 +1882,11 @@ function countStreak( str , i , streaker ) {
|
|
|
1891
1882
|
|
|
1892
1883
|
|
|
1893
1884
|
function searchChildOfType( parent , type ) {
|
|
1894
|
-
var
|
|
1895
|
-
if ( !
|
|
1885
|
+
var parts = parent.parts ;
|
|
1886
|
+
if ( ! parts ) { return null ; }
|
|
1896
1887
|
|
|
1897
|
-
for ( let i = 0 ; i <
|
|
1898
|
-
let child =
|
|
1888
|
+
for ( let i = 0 ; i < parts.length ; i ++ ) {
|
|
1889
|
+
let child = parts[ i ] ;
|
|
1899
1890
|
if ( child.type === type ) { return child ; }
|
|
1900
1891
|
}
|
|
1901
1892
|
|
|
@@ -1905,11 +1896,11 @@ function searchChildOfType( parent , type ) {
|
|
|
1905
1896
|
|
|
1906
1897
|
|
|
1907
1898
|
function searchLastChildOfType( parent , type ) {
|
|
1908
|
-
var
|
|
1909
|
-
if ( !
|
|
1899
|
+
var parts = parent.parts ;
|
|
1900
|
+
if ( ! parts ) { return null ; }
|
|
1910
1901
|
|
|
1911
|
-
for ( let i =
|
|
1912
|
-
let child =
|
|
1902
|
+
for ( let i = parts.length - 1 ; i >= 0 ; i -- ) {
|
|
1903
|
+
let child = parts[ i ] ;
|
|
1913
1904
|
if ( child.type === type ) { return child ; }
|
|
1914
1905
|
}
|
|
1915
1906
|
|
|
@@ -1919,7 +1910,7 @@ function searchLastChildOfType( parent , type ) {
|
|
|
1919
1910
|
|
|
1920
1911
|
|
|
1921
1912
|
function searchColumn( tableRow , column ) {
|
|
1922
|
-
for ( let tableCell of tableRow.
|
|
1913
|
+
for ( let tableCell of tableRow.parts ) {
|
|
1923
1914
|
if ( tableCell.column === column ) { return tableCell ; }
|
|
1924
1915
|
}
|
|
1925
1916
|
|
|
@@ -1936,7 +1927,7 @@ function stack( ctx , parent = ctx.parts[ ctx.parts.length - 1 ] ) {
|
|
|
1936
1927
|
} ) ;
|
|
1937
1928
|
|
|
1938
1929
|
ctx.parent = parent ;
|
|
1939
|
-
ctx.parts = parent.
|
|
1930
|
+
ctx.parts = parent.parts = parent.parts || [] ;
|
|
1940
1931
|
}
|
|
1941
1932
|
|
|
1942
1933
|
|
package/lib/book-source.js
CHANGED
|
@@ -35,6 +35,8 @@ bookSource.StructuredDocument = require( './StructuredDocument.js' ) ;
|
|
|
35
35
|
bookSource.Style = require( './Style.js' ) ;
|
|
36
36
|
bookSource.Theme = require( './Theme.js' ) ;
|
|
37
37
|
|
|
38
|
+
Object.assign( bookSource , require( './documentParts.js' ) ) ;
|
|
39
|
+
|
|
38
40
|
// Exposed external lib
|
|
39
41
|
const paletteShade = require( 'palette-shade' ) ;
|
|
40
42
|
bookSource.Color = paletteShade.Color ;
|
|
@@ -0,0 +1,445 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Book Source
|
|
3
|
+
|
|
4
|
+
Copyright (c) 2023 Cédric Ronvel
|
|
5
|
+
|
|
6
|
+
The MIT License (MIT)
|
|
7
|
+
|
|
8
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
9
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
10
|
+
in the Software without restriction, including without limitation the rights
|
|
11
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
12
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
13
|
+
furnished to do so, subject to the following conditions:
|
|
14
|
+
|
|
15
|
+
The above copyright notice and this permission notice shall be included in all
|
|
16
|
+
copies or substantial portions of the Software.
|
|
17
|
+
|
|
18
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
19
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
20
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
21
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
22
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
23
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
24
|
+
SOFTWARE.
|
|
25
|
+
*/
|
|
26
|
+
|
|
27
|
+
"use strict" ;
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
const documentParts = {} ;
|
|
32
|
+
module.exports = documentParts ;
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
function Part() {
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
documentParts.Part = Part ;
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
function InlinePart() {
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
InlinePart.prototype = Object.create( Part.prototype ) ;
|
|
47
|
+
InlinePart.prototype.constructor = InlinePart ;
|
|
48
|
+
documentParts.InlinePart = InlinePart ;
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
function InlineTextPart( text ) {
|
|
53
|
+
this.text = text ;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
InlineTextPart.prototype = Object.create( Part.prototype ) ;
|
|
57
|
+
InlineTextPart.prototype.constructor = InlineTextPart ;
|
|
58
|
+
documentParts.InlineTextPart = InlineTextPart ;
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
function BlockPart() {
|
|
63
|
+
this.parts = [] ;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
BlockPart.prototype = Object.create( Part.prototype ) ;
|
|
67
|
+
BlockPart.prototype.constructor = BlockPart ;
|
|
68
|
+
documentParts.BlockPart = BlockPart ;
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
// Inline Parts
|
|
73
|
+
|
|
74
|
+
function Text( text ) {
|
|
75
|
+
this.type = 'text' ;
|
|
76
|
+
InlineTextPart.call( this , text ) ;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
Text.prototype = Object.create( InlineTextPart.prototype ) ;
|
|
80
|
+
Text.prototype.constructor = Text ;
|
|
81
|
+
documentParts.Text = Text ;
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
function EmphasisText( text , level ) {
|
|
86
|
+
this.type = 'emphasisText' ;
|
|
87
|
+
this.level = level ;
|
|
88
|
+
InlineTextPart.call( this , text ) ;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
EmphasisText.prototype = Object.create( InlineTextPart.prototype ) ;
|
|
92
|
+
EmphasisText.prototype.constructor = EmphasisText ;
|
|
93
|
+
documentParts.EmphasisText = EmphasisText ;
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
function DecoratedText( text , level ) {
|
|
98
|
+
this.type = 'decoratedText' ;
|
|
99
|
+
this.level = level ;
|
|
100
|
+
this.underline = true ;
|
|
101
|
+
InlineTextPart.call( this , text ) ;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
DecoratedText.prototype = Object.create( InlineTextPart.prototype ) ;
|
|
105
|
+
DecoratedText.prototype.constructor = DecoratedText ;
|
|
106
|
+
documentParts.DecoratedText = DecoratedText ;
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
|
|
110
|
+
function Code( text ) {
|
|
111
|
+
this.type = 'code' ;
|
|
112
|
+
InlineTextPart.call( this , text ) ;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
Code.prototype = Object.create( InlineTextPart.prototype ) ;
|
|
116
|
+
Code.prototype.constructor = Code ;
|
|
117
|
+
documentParts.Code = Code ;
|
|
118
|
+
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
function Link( text , href , style , title ) {
|
|
122
|
+
this.type = 'link' ;
|
|
123
|
+
this.href = href ;
|
|
124
|
+
this.style = style || undefined ;
|
|
125
|
+
InlineTextPart.call( this , text ) ;
|
|
126
|
+
this.title = title || undefined ;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
Link.prototype = Object.create( InlineTextPart.prototype ) ;
|
|
130
|
+
Link.prototype.constructor = Link ;
|
|
131
|
+
documentParts.Link = Link ;
|
|
132
|
+
|
|
133
|
+
|
|
134
|
+
|
|
135
|
+
function StyledText( text , style , title ) {
|
|
136
|
+
this.type = 'styledText' ;
|
|
137
|
+
this.style = style || undefined ;
|
|
138
|
+
InlineTextPart.call( this , text ) ;
|
|
139
|
+
this.title = title || undefined ;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
StyledText.prototype = Object.create( InlineTextPart.prototype ) ;
|
|
143
|
+
StyledText.prototype.constructor = StyledText ;
|
|
144
|
+
documentParts.StyledText = StyledText ;
|
|
145
|
+
|
|
146
|
+
|
|
147
|
+
|
|
148
|
+
function Image( href , altText , title ) {
|
|
149
|
+
this.type = 'image' ;
|
|
150
|
+
this.href = href ;
|
|
151
|
+
this.altText = altText ;
|
|
152
|
+
this.title = title || undefined ;
|
|
153
|
+
InlinePart.call( this ) ;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
Image.prototype = Object.create( InlinePart.prototype ) ;
|
|
157
|
+
Image.prototype.constructor = Image ;
|
|
158
|
+
documentParts.Image = Image ;
|
|
159
|
+
|
|
160
|
+
|
|
161
|
+
|
|
162
|
+
const emoji = require( 'string-kit/lib/emoji.js' ) ;
|
|
163
|
+
|
|
164
|
+
function Pictogram( code , altText , title ) {
|
|
165
|
+
this.type = 'pictogram' ;
|
|
166
|
+
this.code = code ;
|
|
167
|
+
|
|
168
|
+
var emojiChar = emoji.get( this.code ) ;
|
|
169
|
+
this.emoji = emojiChar || undefined ;
|
|
170
|
+
|
|
171
|
+
this.altText =
|
|
172
|
+
altText ? altText :
|
|
173
|
+
emojiChar ? emoji.getCanonicalName( emojiChar ) :
|
|
174
|
+
undefined ;
|
|
175
|
+
|
|
176
|
+
this.title = title || undefined ;
|
|
177
|
+
|
|
178
|
+
InlinePart.call( this ) ;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
Pictogram.prototype = Object.create( InlinePart.prototype ) ;
|
|
182
|
+
Pictogram.prototype.constructor = Pictogram ;
|
|
183
|
+
documentParts.Pictogram = Pictogram ;
|
|
184
|
+
|
|
185
|
+
|
|
186
|
+
|
|
187
|
+
// Block parts
|
|
188
|
+
|
|
189
|
+
function Paragraph() {
|
|
190
|
+
this.type = 'paragraph' ;
|
|
191
|
+
BlockPart.call( this ) ;
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
Paragraph.prototype = Object.create( BlockPart.prototype ) ;
|
|
195
|
+
Paragraph.prototype.constructor = Paragraph ;
|
|
196
|
+
documentParts.Paragraph = Paragraph ;
|
|
197
|
+
|
|
198
|
+
|
|
199
|
+
|
|
200
|
+
function Header( level ) {
|
|
201
|
+
this.type = 'header' ;
|
|
202
|
+
this.level = level ;
|
|
203
|
+
BlockPart.call( this ) ;
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
Header.prototype = Object.create( BlockPart.prototype ) ;
|
|
207
|
+
Header.prototype.constructor = Header ;
|
|
208
|
+
documentParts.Header = Header ;
|
|
209
|
+
|
|
210
|
+
|
|
211
|
+
|
|
212
|
+
function Cite() {
|
|
213
|
+
this.type = 'cite' ;
|
|
214
|
+
BlockPart.call( this ) ;
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
Cite.prototype = Object.create( BlockPart.prototype ) ;
|
|
218
|
+
Cite.prototype.constructor = Cite ;
|
|
219
|
+
documentParts.Cite = Cite ;
|
|
220
|
+
|
|
221
|
+
|
|
222
|
+
|
|
223
|
+
function List( indent ) {
|
|
224
|
+
this.type = 'list' ;
|
|
225
|
+
this.indent = indent ;
|
|
226
|
+
BlockPart.call( this ) ;
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
List.prototype = Object.create( BlockPart.prototype ) ;
|
|
230
|
+
List.prototype.constructor = List ;
|
|
231
|
+
documentParts.List = List ;
|
|
232
|
+
|
|
233
|
+
|
|
234
|
+
|
|
235
|
+
function ListItem( indent ) {
|
|
236
|
+
this.type = 'listItem' ;
|
|
237
|
+
this.indent = indent ;
|
|
238
|
+
BlockPart.call( this ) ;
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
ListItem.prototype = Object.create( BlockPart.prototype ) ;
|
|
242
|
+
ListItem.prototype.constructor = ListItem ;
|
|
243
|
+
documentParts.ListItem = ListItem ;
|
|
244
|
+
|
|
245
|
+
|
|
246
|
+
|
|
247
|
+
function OrderedList( indent ) {
|
|
248
|
+
this.type = 'orderedList' ;
|
|
249
|
+
this.indent = indent ;
|
|
250
|
+
BlockPart.call( this ) ;
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
OrderedList.prototype = Object.create( BlockPart.prototype ) ;
|
|
254
|
+
OrderedList.prototype.constructor = OrderedList ;
|
|
255
|
+
documentParts.OrderedList = OrderedList ;
|
|
256
|
+
|
|
257
|
+
|
|
258
|
+
|
|
259
|
+
function OrderedListItem( indent , order ) {
|
|
260
|
+
this.type = 'orderedListItem' ;
|
|
261
|
+
this.indent = indent ;
|
|
262
|
+
this.order = order ;
|
|
263
|
+
BlockPart.call( this ) ;
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
OrderedListItem.prototype = Object.create( BlockPart.prototype ) ;
|
|
267
|
+
OrderedListItem.prototype.constructor = OrderedListItem ;
|
|
268
|
+
documentParts.OrderedListItem = OrderedListItem ;
|
|
269
|
+
|
|
270
|
+
|
|
271
|
+
|
|
272
|
+
function Quote( indent ) {
|
|
273
|
+
this.type = 'quote' ;
|
|
274
|
+
this.indent = indent ;
|
|
275
|
+
BlockPart.call( this ) ;
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
Quote.prototype = Object.create( BlockPart.prototype ) ;
|
|
279
|
+
Quote.prototype.constructor = Quote ;
|
|
280
|
+
documentParts.Quote = Quote ;
|
|
281
|
+
|
|
282
|
+
|
|
283
|
+
|
|
284
|
+
function HorizontalRule( clearFloat ) {
|
|
285
|
+
this.type = 'horizontalRule' ;
|
|
286
|
+
this.clearFloat = clearFloat ;
|
|
287
|
+
BlockPart.call( this ) ;
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
HorizontalRule.prototype = Object.create( BlockPart.prototype ) ;
|
|
291
|
+
HorizontalRule.prototype.constructor = HorizontalRule ;
|
|
292
|
+
documentParts.HorizontalRule = HorizontalRule ;
|
|
293
|
+
|
|
294
|
+
|
|
295
|
+
|
|
296
|
+
function ClearFloat() {
|
|
297
|
+
this.type = 'clearFloat' ;
|
|
298
|
+
BlockPart.call( this ) ;
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
ClearFloat.prototype = Object.create( BlockPart.prototype ) ;
|
|
302
|
+
ClearFloat.prototype.constructor = ClearFloat ;
|
|
303
|
+
documentParts.ClearFloat = ClearFloat ;
|
|
304
|
+
|
|
305
|
+
|
|
306
|
+
|
|
307
|
+
function CodeBlock( text , lang ) {
|
|
308
|
+
this.type = 'codeBlock' ;
|
|
309
|
+
this.lang = lang || undefined ;
|
|
310
|
+
this.text = text ;
|
|
311
|
+
BlockPart.call( this ) ;
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
CodeBlock.prototype = Object.create( BlockPart.prototype ) ;
|
|
315
|
+
CodeBlock.prototype.constructor = CodeBlock ;
|
|
316
|
+
documentParts.CodeBlock = CodeBlock ;
|
|
317
|
+
|
|
318
|
+
|
|
319
|
+
|
|
320
|
+
function Anchor( href ) {
|
|
321
|
+
this.type = 'anchor' ;
|
|
322
|
+
this.href = href ;
|
|
323
|
+
BlockPart.call( this ) ;
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
Anchor.prototype = Object.create( BlockPart.prototype ) ;
|
|
327
|
+
Anchor.prototype.constructor = Anchor ;
|
|
328
|
+
documentParts.Anchor = Anchor ;
|
|
329
|
+
|
|
330
|
+
|
|
331
|
+
|
|
332
|
+
function Table() {
|
|
333
|
+
this.type = 'table' ;
|
|
334
|
+
this.columns = [] ;
|
|
335
|
+
this.multilineRowMode = false ;
|
|
336
|
+
this.hasHeadSeparator = false ;
|
|
337
|
+
this.hasRowSeparator = false ;
|
|
338
|
+
BlockPart.call( this ) ;
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
Table.prototype = Object.create( BlockPart.prototype ) ;
|
|
342
|
+
Table.prototype.constructor = Table ;
|
|
343
|
+
documentParts.Table = Table ;
|
|
344
|
+
|
|
345
|
+
|
|
346
|
+
|
|
347
|
+
function TableCaption( style ) {
|
|
348
|
+
this.type = 'tableCaption' ;
|
|
349
|
+
this.style = style || undefined ;
|
|
350
|
+
BlockPart.call( this ) ;
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
TableCaption.prototype = Object.create( BlockPart.prototype ) ;
|
|
354
|
+
TableCaption.prototype.constructor = TableCaption ;
|
|
355
|
+
documentParts.TableCaption = TableCaption ;
|
|
356
|
+
|
|
357
|
+
|
|
358
|
+
|
|
359
|
+
function TableRow( style ) {
|
|
360
|
+
this.type = 'tableRow' ;
|
|
361
|
+
this.style = style || undefined ;
|
|
362
|
+
this.rowSeparator = false ;
|
|
363
|
+
this.continueRowSpan = undefined ;
|
|
364
|
+
BlockPart.call( this ) ;
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
TableRow.prototype = Object.create( BlockPart.prototype ) ;
|
|
368
|
+
TableRow.prototype.constructor = TableRow ;
|
|
369
|
+
documentParts.TableRow = TableRow ;
|
|
370
|
+
|
|
371
|
+
TableRow.prototype.toHead = function() {
|
|
372
|
+
var tableHeadRow = new TableHeadRow( this.style ) ;
|
|
373
|
+
tableHeadRow.rowSeparator = this.rowSeparator ;
|
|
374
|
+
tableHeadRow.continueRowSpan = this.continueRowSpan ;
|
|
375
|
+
tableHeadRow.parts = this.parts ;
|
|
376
|
+
return tableHeadRow ;
|
|
377
|
+
} ;
|
|
378
|
+
|
|
379
|
+
|
|
380
|
+
|
|
381
|
+
function TableHeadRow( style ) {
|
|
382
|
+
this.type = 'tableHeadRow' ;
|
|
383
|
+
this.style = style || undefined ;
|
|
384
|
+
this.rowSeparator = false ;
|
|
385
|
+
this.continueRowSpan = undefined ;
|
|
386
|
+
BlockPart.call( this ) ;
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
TableHeadRow.prototype = Object.create( BlockPart.prototype ) ;
|
|
390
|
+
TableHeadRow.prototype.constructor = TableHeadRow ;
|
|
391
|
+
documentParts.TableHeadRow = TableHeadRow ;
|
|
392
|
+
|
|
393
|
+
|
|
394
|
+
|
|
395
|
+
function TableCell( style ) {
|
|
396
|
+
this.type = 'tableCell' ;
|
|
397
|
+
this.style = style || undefined ;
|
|
398
|
+
this.column = - 1 ; // The column index
|
|
399
|
+
this.columnSeparator = false ;
|
|
400
|
+
this.columnSpan = 1 ;
|
|
401
|
+
this.rowSpan = 1 ;
|
|
402
|
+
this.sx = - 1 ;
|
|
403
|
+
this.ex = - 1 ;
|
|
404
|
+
this.masterCell = undefined ;
|
|
405
|
+
BlockPart.call( this ) ;
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
TableCell.prototype = Object.create( BlockPart.prototype ) ;
|
|
409
|
+
TableCell.prototype.constructor = TableCell ;
|
|
410
|
+
documentParts.TableCell = TableCell ;
|
|
411
|
+
|
|
412
|
+
TableCell.prototype.toHead = function() {
|
|
413
|
+
var tableHeadCell = new TableHeadCell( this.style ) ;
|
|
414
|
+
tableHeadCell.column = this.column ;
|
|
415
|
+
tableHeadCell.columnSeparator = this.columnSeparator ;
|
|
416
|
+
tableHeadCell.columnSpan = this.columnSpan ;
|
|
417
|
+
tableHeadCell.rowSpan = this.rowSpan ;
|
|
418
|
+
tableHeadCell.sx = this.sx ;
|
|
419
|
+
tableHeadCell.ex = this.ex ;
|
|
420
|
+
tableHeadCell.masterCell = this.masterCell ;
|
|
421
|
+
tableHeadCell.parts = this.parts ;
|
|
422
|
+
return tableHeadCell ;
|
|
423
|
+
} ;
|
|
424
|
+
|
|
425
|
+
|
|
426
|
+
|
|
427
|
+
function TableHeadCell( style ) {
|
|
428
|
+
this.type = 'tableHeadCell' ;
|
|
429
|
+
this.style = style || undefined ;
|
|
430
|
+
this.column = - 1 ;
|
|
431
|
+
this.columnSeparator = false ;
|
|
432
|
+
this.columnSpan = 1 ;
|
|
433
|
+
this.rowSpan = 1 ;
|
|
434
|
+
this.sx = - 1 ;
|
|
435
|
+
this.ex = - 1 ;
|
|
436
|
+
this.masterCell = undefined ;
|
|
437
|
+
this.isColumnHead = false ;
|
|
438
|
+
this.isRowHead = false ;
|
|
439
|
+
BlockPart.call( this ) ;
|
|
440
|
+
}
|
|
441
|
+
|
|
442
|
+
TableHeadCell.prototype = Object.create( BlockPart.prototype ) ;
|
|
443
|
+
TableHeadCell.prototype.constructor = TableHeadCell ;
|
|
444
|
+
documentParts.TableHeadCell = TableHeadCell ;
|
|
445
|
+
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "book-source",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.2",
|
|
4
4
|
"description": "A lightweight markup language, inspired by Markdown.",
|
|
5
5
|
"main": "lib/book-source.js",
|
|
6
6
|
"directories": {
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
},
|
|
9
9
|
"dependencies": {
|
|
10
10
|
"array-kit": "^0.2.6",
|
|
11
|
-
"palette-shade": "^0.1.
|
|
11
|
+
"palette-shade": "^0.1.3",
|
|
12
12
|
"string-kit": "^0.18.0"
|
|
13
13
|
},
|
|
14
14
|
"scripts": {
|