book-source 0.1.1
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/.eslintrc.js +168 -0
- package/Makefile +112 -0
- package/README.md +17 -0
- package/brainstorming +213 -0
- package/css/code.css +120 -0
- package/css/core.css +317 -0
- package/css/standalone.css +30 -0
- package/css/unimplemented.css +65 -0
- package/documentation.md +17 -0
- package/extlib/chromajs.custom.js +865 -0
- package/lib/Color.js +197 -0
- package/lib/HtmlRenderer.js +618 -0
- package/lib/Palette.js +313 -0
- package/lib/StructuredDocument.js +1973 -0
- package/lib/Style.js +102 -0
- package/lib/Theme.js +127 -0
- package/lib/book-source.js +68 -0
- package/package.json +38 -0
package/lib/Style.js
ADDED
|
@@ -0,0 +1,102 @@
|
|
|
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 Color = require( './Color.js' ) ;
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
function Style() {
|
|
36
|
+
this.textColor = null ;
|
|
37
|
+
this.backgroundColor = null ;
|
|
38
|
+
this.bold = null ;
|
|
39
|
+
this.italic = null ;
|
|
40
|
+
this.underline = null ;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
module.exports = Style ;
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
Style.merge = function( ... styles ) {
|
|
48
|
+
var mergedStyle = new Style() ;
|
|
49
|
+
|
|
50
|
+
for ( let style of styles ) {
|
|
51
|
+
if ( style.textColor !== null ) { mergedStyle.textColor = style.textColor ; }
|
|
52
|
+
if ( style.backgroundColor !== null ) { mergedStyle.backgroundColor = style.backgroundColor ; }
|
|
53
|
+
if ( style.bold !== null ) { mergedStyle.bold = style.bold ; }
|
|
54
|
+
if ( style.italic !== null ) { mergedStyle.italic = style.italic ; }
|
|
55
|
+
if ( style.underline !== null ) { mergedStyle.underline = style.underline ; }
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
return mergedStyle ;
|
|
59
|
+
} ;
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
const BOOLEAN_PROPERTIES = new Set( [ 'bold' , 'italic' , 'underline' ] ) ;
|
|
64
|
+
const TEXT_COLOR_PROPERTIES = new Set( [ 'text' , 'tx' , 'foreground' , 'fg' ] ) ;
|
|
65
|
+
const BACKGROUND_COLOR_PROPERTIES = new Set( [ 'background' , 'bg' ] ) ;
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
Style.parse = function( str , forTextElement = true ) {
|
|
70
|
+
var style = new Style() ;
|
|
71
|
+
|
|
72
|
+
for ( let part of str.trim().split( /,/g ) ) {
|
|
73
|
+
let [ property , value ] = part.split( ':' ) ;
|
|
74
|
+
|
|
75
|
+
if ( value ) {
|
|
76
|
+
property = TEXT_COLOR_PROPERTIES.has( property ) ? 'text' :
|
|
77
|
+
BACKGROUND_COLOR_PROPERTIES.has( property ) ? 'background' :
|
|
78
|
+
forTextElement ? 'text' : 'background' ;
|
|
79
|
+
}
|
|
80
|
+
else {
|
|
81
|
+
if ( BOOLEAN_PROPERTIES.has( property ) ) {
|
|
82
|
+
style[ property ] = true ;
|
|
83
|
+
continue ;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
value = property ;
|
|
87
|
+
property = forTextElement ? 'text' : 'background' ;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
switch ( property ) {
|
|
91
|
+
case 'text' :
|
|
92
|
+
style.textColor = Color.parse( value ) ;
|
|
93
|
+
break ;
|
|
94
|
+
case 'background' :
|
|
95
|
+
style.backgroundColor = Color.parse( value ) ;
|
|
96
|
+
break ;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
return style ;
|
|
101
|
+
} ;
|
|
102
|
+
|
package/lib/Theme.js
ADDED
|
@@ -0,0 +1,127 @@
|
|
|
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 Palette = require( './Palette.js' ) ;
|
|
32
|
+
const Color = require( './Color.js' ) ;
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
function Theme( params = {} ) {
|
|
37
|
+
this.colors = {
|
|
38
|
+
background: '%white' ,
|
|
39
|
+
|
|
40
|
+
text: '%black' ,
|
|
41
|
+
linkText: '%blue' ,
|
|
42
|
+
hoverLinkText: '%bright blue' ,
|
|
43
|
+
visitedLinkText: '%blue' ,
|
|
44
|
+
|
|
45
|
+
headerRule: '%brighter gray' ,
|
|
46
|
+
|
|
47
|
+
//quoteBackground: '%lighter blue tint' ,
|
|
48
|
+
quoteBackground: '%brightest blue duller tone' ,
|
|
49
|
+
quote2Background: '%brighter blue duller tone' , // quote in quote
|
|
50
|
+
quote3Background: '%bright blue duller tone' , // quote in quote in quote
|
|
51
|
+
|
|
52
|
+
codeBackground: '%bright blue tint slightly dull' ,
|
|
53
|
+
codeBorder: '%slightly bright blue tint' ,
|
|
54
|
+
|
|
55
|
+
figureCaptionBackground: '%brightest blue dull tone' ,
|
|
56
|
+
|
|
57
|
+
tableRowBackground: '%white' ,
|
|
58
|
+
tableEvenRowBackground: '%lightest blue tint' ,
|
|
59
|
+
tableBorder: '%brighter blue tone slightly dull' ,
|
|
60
|
+
tableCaptionBackground: '%orange' ,
|
|
61
|
+
tableCaptionText: '%white' ,
|
|
62
|
+
tableColumnHead: '%lightest red' ,
|
|
63
|
+
tableRowHead: '%lightest green' ,
|
|
64
|
+
tableBothHead: '%brighter gray'
|
|
65
|
+
} ;
|
|
66
|
+
|
|
67
|
+
this.fonts = {
|
|
68
|
+
main: 'Helvetica,arial,freesans,clean,sans-serif'
|
|
69
|
+
} ;
|
|
70
|
+
|
|
71
|
+
this.sizes = {
|
|
72
|
+
text: '14px' ,
|
|
73
|
+
lineHeight: '1.7' ,
|
|
74
|
+
codeLineHeight: '1.4'
|
|
75
|
+
} ;
|
|
76
|
+
|
|
77
|
+
this.printSizes = {
|
|
78
|
+
text: '9pt' ,
|
|
79
|
+
lineHeight: '1.5' ,
|
|
80
|
+
codeLineHeight: '1.4'
|
|
81
|
+
} ;
|
|
82
|
+
|
|
83
|
+
this.palette = ! params.palette || typeof params.palette !== 'object' ? new Palette() :
|
|
84
|
+
params.palette instanceof Palette ? params.palette :
|
|
85
|
+
new Palette( params.palette ) ;
|
|
86
|
+
|
|
87
|
+
this.set( params ) ;
|
|
88
|
+
if ( this.palette ) { this.substituteWithPalette() ; }
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
module.exports = Theme ;
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
const CATEGORIES = [ 'colors' , 'fonts' , 'sizes' , 'printSizes' ] ;
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
Theme.prototype.set = function( params ) {
|
|
100
|
+
for ( let category of CATEGORIES ) {
|
|
101
|
+
if ( params[ category ] && typeof params[ category ] === 'object' ) {
|
|
102
|
+
for ( let key in params[ category ] ) {
|
|
103
|
+
if ( this[ category ][ key ] !== undefined ) {
|
|
104
|
+
this[ category ][ key ] = params[ category ][ key ] ;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
} ;
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
|
|
113
|
+
Theme.prototype.substituteWithPalette = function() {
|
|
114
|
+
var property , value , colorObject ;
|
|
115
|
+
|
|
116
|
+
for ( property in this.colors ) {
|
|
117
|
+
value = this.colors[ property ] ;
|
|
118
|
+
|
|
119
|
+
if ( value[ 0 ] === '%' ) {
|
|
120
|
+
colorObject = Color.parse( value.slice( 1 ) ) ;
|
|
121
|
+
if ( this.palette.has( colorObject ) ) {
|
|
122
|
+
this.colors[ property ] = colorObject ;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
} ;
|
|
127
|
+
|
|
@@ -0,0 +1,68 @@
|
|
|
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 bookSource = {} ;
|
|
32
|
+
module.exports = bookSource ;
|
|
33
|
+
|
|
34
|
+
bookSource.StructuredDocument = require( './StructuredDocument.js' ) ;
|
|
35
|
+
bookSource.Style = require( './Style.js' ) ;
|
|
36
|
+
bookSource.Color = require( './Color.js' ) ;
|
|
37
|
+
|
|
38
|
+
bookSource.Palette = require( './Palette.js' ) ;
|
|
39
|
+
bookSource.Theme = require( './Theme.js' ) ;
|
|
40
|
+
bookSource.HtmlRenderer = require( './HtmlRenderer.js' ) ;
|
|
41
|
+
|
|
42
|
+
bookSource.parse = bookSource.StructuredDocument.parse ;
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
const path = require( 'path' ) ;
|
|
47
|
+
|
|
48
|
+
bookSource.getBuiltinCssPath = type => {
|
|
49
|
+
switch ( type ) {
|
|
50
|
+
case 'core' :
|
|
51
|
+
case 'standalone' :
|
|
52
|
+
case 'code' :
|
|
53
|
+
return path.join( __dirname , '..' , 'css' , type + '.css' ) ;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
throw new Error( "There is no built-in CSS of type '" + type + "'" ) ;
|
|
57
|
+
} ;
|
|
58
|
+
|
|
59
|
+
bookSource.getBuiltinCssSync = type => {
|
|
60
|
+
const fs = require( 'fs' ) ;
|
|
61
|
+
return fs.readFileSync( bookSource.getBuiltinCssPath( type ) , 'utf8' ) ;
|
|
62
|
+
} ;
|
|
63
|
+
|
|
64
|
+
bookSource.getBuiltinCss = type => {
|
|
65
|
+
const fs = require( 'fs' ) ;
|
|
66
|
+
return fs.promises.readFile( bookSource.getBuiltinCssPath( type ) , 'utf8' ) ;
|
|
67
|
+
} ;
|
|
68
|
+
|
package/package.json
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "book-source",
|
|
3
|
+
"version": "0.1.1",
|
|
4
|
+
"description": "A lightweight markup language, inspired by Markdown",
|
|
5
|
+
"main": "lib/book-source.js",
|
|
6
|
+
"directories": {
|
|
7
|
+
"test": "test"
|
|
8
|
+
},
|
|
9
|
+
"dependencies": {
|
|
10
|
+
"array-kit": "^0.2.6",
|
|
11
|
+
"highlight.js": "^11.9.0",
|
|
12
|
+
"string-kit": "^0.18.0"
|
|
13
|
+
},
|
|
14
|
+
"scripts": {
|
|
15
|
+
"test": "tea-time -R dot"
|
|
16
|
+
},
|
|
17
|
+
"repository": {
|
|
18
|
+
"type": "git",
|
|
19
|
+
"url": "https://github.com/cronvel/book-source.git"
|
|
20
|
+
},
|
|
21
|
+
"keywords": [
|
|
22
|
+
"markup",
|
|
23
|
+
"book",
|
|
24
|
+
"source"
|
|
25
|
+
],
|
|
26
|
+
"author": "Cédric Ronvel",
|
|
27
|
+
"license": "MIT",
|
|
28
|
+
"bugs": {
|
|
29
|
+
"url": "https://github.com/cronvel/book-source/issues"
|
|
30
|
+
},
|
|
31
|
+
"copyright": {
|
|
32
|
+
"title": "Book Source",
|
|
33
|
+
"years": [
|
|
34
|
+
2023
|
|
35
|
+
],
|
|
36
|
+
"owner": "Cédric Ronvel"
|
|
37
|
+
}
|
|
38
|
+
}
|