markdown-up 3.12.2 → 4.0.0
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 +33 -9
- package/lib/app.js +48 -18
- package/lib/appImports.js +29 -0
- package/lib/script.js +7 -94
- package/lib/scriptLibrary.js +73 -724
- package/package.json +7 -6
- package/lib/dataTable.js +0 -219
- package/lib/dataUtil.js +0 -72
- package/lib/lineChart.js +0 -718
package/README.md
CHANGED
|
@@ -26,11 +26,26 @@ markdown-up
|
|
|
26
26
|
|
|
27
27
|
## Host Markdown Web Pages
|
|
28
28
|
|
|
29
|
-
To host a Markdown resource,
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
~~~
|
|
33
|
-
|
|
29
|
+
To host a Markdown resource, add the MarkdownUp application HTML stub to the directory containing
|
|
30
|
+
your Markdown files:
|
|
31
|
+
|
|
32
|
+
~~~ html
|
|
33
|
+
<!DOCTYPE html>
|
|
34
|
+
<html lang="en">
|
|
35
|
+
<head>
|
|
36
|
+
<title>MarkdownUp</title>
|
|
37
|
+
<meta charset="utf-8">
|
|
38
|
+
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
39
|
+
<link rel="stylesheet" href="https://craigahobbs.github.io/markdown-up/app.css">
|
|
40
|
+
<link rel="preload" href="https://craigahobbs.github.io/markdown-up/bare-script/static/markdown.css" as="style">
|
|
41
|
+
<link rel="modulepreload" href="https://craigahobbs.github.io/markdown-up/lib/appImports.js" as="script">
|
|
42
|
+
</head>
|
|
43
|
+
<script type="module">
|
|
44
|
+
import {MarkdownUp} from 'https://craigahobbs.github.io/markdown-up/lib/appImports.js';
|
|
45
|
+
const app = new MarkdownUp(window);
|
|
46
|
+
app.run();
|
|
47
|
+
</script>
|
|
48
|
+
</html>
|
|
34
49
|
~~~
|
|
35
50
|
|
|
36
51
|
To test your Markdown page, start a local static web server:
|
|
@@ -42,14 +57,23 @@ python3 -m http.server
|
|
|
42
57
|
By default, MarkdownUp fetches the "README.md" resource. To change the default resource, update the
|
|
43
58
|
application stub file, index.html. For example:
|
|
44
59
|
|
|
45
|
-
~~~
|
|
46
|
-
|
|
60
|
+
~~~ html
|
|
61
|
+
<!DOCTYPE html>
|
|
62
|
+
<html lang="en">
|
|
63
|
+
<head>
|
|
64
|
+
<title>MarkdownUp</title>
|
|
65
|
+
<meta charset="utf-8">
|
|
66
|
+
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
67
|
+
<link rel="stylesheet" href="https://craigahobbs.github.io/markdown-up/app.css">
|
|
68
|
+
<link rel="preload" href="https://craigahobbs.github.io/markdown-up/bare-script/static/markdown.css" as="style">
|
|
69
|
+
<link rel="modulepreload" href="https://craigahobbs.github.io/markdown-up/lib/appImports.js" as="script">
|
|
70
|
+
</head>
|
|
47
71
|
<script type="module">
|
|
48
|
-
import {MarkdownUp} from 'https://craigahobbs.github.io/markdown-up/lib/
|
|
72
|
+
import {MarkdownUp} from 'https://craigahobbs.github.io/markdown-up/lib/appImports.js';
|
|
49
73
|
const app = new MarkdownUp(window, {'url': 'other.md'});
|
|
50
74
|
app.run();
|
|
51
75
|
</script>
|
|
52
|
-
|
|
76
|
+
</html>
|
|
53
77
|
~~~
|
|
54
78
|
|
|
55
79
|
To view a different Markdown resource, set the application's "url" hash parameter (i.e.,
|
package/lib/app.js
CHANGED
|
@@ -5,10 +5,9 @@
|
|
|
5
5
|
|
|
6
6
|
import {MarkdownScriptRuntime, markdownScriptCodeBlock} from './script.js';
|
|
7
7
|
import {decodeQueryString, encodeQueryString, jsonStringifySortKeys} from 'schema-markdown/lib/encode.js';
|
|
8
|
-
import {
|
|
8
|
+
import {elementModelWrapCallbacks, markdownScriptFunctions} from './scriptLibrary.js';
|
|
9
9
|
import {evaluateExpression} from 'bare-script/lib/runtime.js';
|
|
10
|
-
import {
|
|
11
|
-
import {markdownScriptFunctions} from './scriptLibrary.js';
|
|
10
|
+
import {executeScriptAsync} from 'bare-script/lib/runtimeAsync.js';
|
|
12
11
|
import {parseExpression} from 'bare-script/lib/parser.js';
|
|
13
12
|
import {parseSchemaMarkdown} from 'schema-markdown/lib/parser.js';
|
|
14
13
|
import {renderElements} from 'element-model/lib/elementModel.js';
|
|
@@ -66,7 +65,7 @@ enum MarkdownUpView
|
|
|
66
65
|
*
|
|
67
66
|
* @typedef {Object} MarkdownUpOptions
|
|
68
67
|
* @property {?Object.<string, function>} [codeBlocks = null] - The
|
|
69
|
-
* [code block]
|
|
68
|
+
* [code block](https://craigahobbs.github.io/bare-script/library/model.html#var.vName='MarkdownElementsOptions')
|
|
70
69
|
* render function map
|
|
71
70
|
* @property {?boolean} [darkMode = false] - If true, use dark mode by default
|
|
72
71
|
* @property {?number} [fontSize = 12] - The font size, in points
|
|
@@ -80,6 +79,14 @@ enum MarkdownUpView
|
|
|
80
79
|
*/
|
|
81
80
|
|
|
82
81
|
|
|
82
|
+
// The default system include path prefix
|
|
83
|
+
const defaultSystemPrefix = 'https://craigahobbs.github.io/markdown-up/include/';
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
// The default application help URL
|
|
87
|
+
const defaultHelpURL = 'https://craigahobbs.github.io/markdown-up-py/';
|
|
88
|
+
|
|
89
|
+
|
|
83
90
|
/**
|
|
84
91
|
* The MarkdownUp application
|
|
85
92
|
*/
|
|
@@ -100,11 +107,11 @@ export class MarkdownUp {
|
|
|
100
107
|
(this.window.matchMedia && this.window.matchMedia('(prefers-color-scheme: dark)').matches);
|
|
101
108
|
this.fontSize = (options !== null ? options.fontSize : null) ?? 12;
|
|
102
109
|
this.globals = (options !== null ? options.globals : null) ?? null;
|
|
103
|
-
this.helpURL = (options !== null ? options.helpURL : null) ??
|
|
110
|
+
this.helpURL = (options !== null ? options.helpURL : null) ?? defaultHelpURL;
|
|
104
111
|
this.lineHeight = (options !== null ? options.lineHeight : null) ?? 1.2;
|
|
105
112
|
this.markdownText = (options !== null ? options.markdownText : null) ?? null;
|
|
106
113
|
this.menu = (options !== null ? options.menu : null) ?? true;
|
|
107
|
-
this.systemPrefix = (options !== null ? options.systemPrefix : null) ??
|
|
114
|
+
this.systemPrefix = (options !== null ? options.systemPrefix : null) ?? defaultSystemPrefix;
|
|
108
115
|
this.url = (options !== null ? options.url : null) ?? 'README.md';
|
|
109
116
|
this.runtimeDocumentKeyDown = null;
|
|
110
117
|
this.runtimeWindowResize = null;
|
|
@@ -145,15 +152,15 @@ export class MarkdownUp {
|
|
|
145
152
|
|
|
146
153
|
// Set the colors
|
|
147
154
|
const isDarkMode = this.paramsLocal.darkMode ?? this.darkMode;
|
|
148
|
-
this.window.document.documentElement.style.setProperty('--
|
|
155
|
+
this.window.document.documentElement.style.setProperty('--barescript-dark-mode', isDarkMode ? '1' : '0');
|
|
149
156
|
|
|
150
157
|
// Set the font size
|
|
151
158
|
const fontSize = this.paramsLocal.fontSize ?? this.fontSize;
|
|
152
|
-
this.window.document.documentElement.style.setProperty('--
|
|
159
|
+
this.window.document.documentElement.style.setProperty('--barescript-font-size', `${fontSize}pt`);
|
|
153
160
|
|
|
154
161
|
// Set the line height
|
|
155
162
|
const lineHeight = this.paramsLocal.lineHeight ?? this.lineHeight;
|
|
156
|
-
this.window.document.documentElement.style.setProperty('--
|
|
163
|
+
this.window.document.documentElement.style.setProperty('--barescript-line-height', `${lineHeight}em`);
|
|
157
164
|
|
|
158
165
|
// Call the application main and validate the result
|
|
159
166
|
this.runtimeCount += 1;
|
|
@@ -296,6 +303,30 @@ export class MarkdownUp {
|
|
|
296
303
|
const url = this.getResourceURL();
|
|
297
304
|
const scriptOptions = this.createScriptOptions();
|
|
298
305
|
|
|
306
|
+
// Load BareScript
|
|
307
|
+
const includeScript = {
|
|
308
|
+
'statements': [
|
|
309
|
+
{
|
|
310
|
+
'include': {
|
|
311
|
+
'includes': [
|
|
312
|
+
{'url': 'markdown.bare', 'system': true},
|
|
313
|
+
{'url': 'markdownHighlight.bare', 'system': true},
|
|
314
|
+
{'url': 'markdownElements.bare', 'system': true},
|
|
315
|
+
{'url': 'markdownParser.bare', 'system': true},
|
|
316
|
+
|
|
317
|
+
// Additional common includes
|
|
318
|
+
{'url': 'args.bare', 'system': true}
|
|
319
|
+
]
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
]
|
|
323
|
+
};
|
|
324
|
+
await executeScriptAsync(includeScript, scriptOptions);
|
|
325
|
+
const getMarkdownTitle = (markdown) => scriptOptions.globals.markdownTitle([markdown], scriptOptions);
|
|
326
|
+
const markdownElementsAsync =
|
|
327
|
+
(markdown, markdownOptions) => scriptOptions.globals.markdownElementsAsync([markdown, markdownOptions], scriptOptions);
|
|
328
|
+
const parseMarkdown = (text) => scriptOptions.globals.markdownParse([text], scriptOptions);
|
|
329
|
+
|
|
299
330
|
// Get the Markdown text
|
|
300
331
|
let markdownText;
|
|
301
332
|
let timeBegin;
|
|
@@ -361,9 +392,11 @@ export class MarkdownUp {
|
|
|
361
392
|
const scriptMarkdownOptions = {...scriptOptions.markdownOptions};
|
|
362
393
|
scriptMarkdownOptions.codeBlocks = {...scriptMarkdownOptions.codeBlocks};
|
|
363
394
|
scriptMarkdownOptions.codeBlocks['markdown-script'] =
|
|
364
|
-
(codeBlock,
|
|
395
|
+
([codeBlock], fnScriptOptions) => markdownScriptCodeBlock(codeBlock, fnScriptOptions);
|
|
365
396
|
|
|
366
397
|
// Render the Markdown
|
|
398
|
+
const contentElements = await markdownElementsAsync(markdownModel, scriptMarkdownOptions);
|
|
399
|
+
elementModelWrapCallbacks(contentElements, scriptOptions);
|
|
367
400
|
const result = {
|
|
368
401
|
'title': markdownTitle,
|
|
369
402
|
'elements': [
|
|
@@ -371,7 +404,7 @@ export class MarkdownUp {
|
|
|
371
404
|
this.burgerElements(),
|
|
372
405
|
|
|
373
406
|
// Render the markdown
|
|
374
|
-
|
|
407
|
+
contentElements
|
|
375
408
|
]
|
|
376
409
|
};
|
|
377
410
|
|
|
@@ -418,16 +451,13 @@ export class MarkdownUp {
|
|
|
418
451
|
|
|
419
452
|
createScriptOptions() {
|
|
420
453
|
// Create the markdown options object
|
|
421
|
-
const urlFn = (url) => this.modifyURL(url);
|
|
422
454
|
const markdownOptions = {
|
|
423
455
|
'codeBlocks': this.codeBlocks ?? {},
|
|
424
|
-
|
|
456
|
+
'copyLinks': true,
|
|
457
|
+
'urlFn': ([url]) => this.modifyURL(url),
|
|
425
458
|
'headerIds': true,
|
|
426
|
-
'usedHeaderIds':
|
|
459
|
+
'usedHeaderIds': {}
|
|
427
460
|
};
|
|
428
|
-
if (this.window.navigator.clipboard) {
|
|
429
|
-
markdownOptions.copyFn = (text) => this.window.navigator.clipboard.writeText(text);
|
|
430
|
-
}
|
|
431
461
|
|
|
432
462
|
// Create the script options object
|
|
433
463
|
const logFn = (text) => {
|
|
@@ -442,7 +472,7 @@ export class MarkdownUp {
|
|
|
442
472
|
markdownOptions,
|
|
443
473
|
'params': this.params,
|
|
444
474
|
'systemPrefix': this.systemPrefix,
|
|
445
|
-
urlFn,
|
|
475
|
+
'urlFn': (url) => this.modifyURL(url),
|
|
446
476
|
'window': this.window
|
|
447
477
|
};
|
|
448
478
|
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
// Licensed under the MIT License
|
|
2
|
+
// https://github.com/craigahobbs/markdown-up/blob/main/LICENSE
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
// Bulk-import JavaScript
|
|
6
|
+
|
|
7
|
+
// bare-script
|
|
8
|
+
import 'bare-script/lib/library.js';
|
|
9
|
+
import 'bare-script/lib/model.js';
|
|
10
|
+
import 'bare-script/lib/options.js';
|
|
11
|
+
import 'bare-script/lib/parser.js';
|
|
12
|
+
import 'bare-script/lib/runtime.js';
|
|
13
|
+
import 'bare-script/lib/runtimeAsync.js';
|
|
14
|
+
import 'bare-script/lib/value.js';
|
|
15
|
+
|
|
16
|
+
// element-model
|
|
17
|
+
import 'element-model/lib/elementModel.js';
|
|
18
|
+
|
|
19
|
+
// markdown-up
|
|
20
|
+
export {MarkdownUp} from './app.js';
|
|
21
|
+
import './script.js';
|
|
22
|
+
import './scriptLibrary.js';
|
|
23
|
+
|
|
24
|
+
// schema-markdown
|
|
25
|
+
import 'schema-markdown/lib/encode.js';
|
|
26
|
+
import 'schema-markdown/lib/parser.js';
|
|
27
|
+
import 'schema-markdown/lib/schema.js';
|
|
28
|
+
import 'schema-markdown/lib/schemaUtil.js';
|
|
29
|
+
import 'schema-markdown/lib/typeModel.js';
|
package/lib/script.js
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
// Licensed under the MIT License
|
|
2
2
|
// https://github.com/craigahobbs/markdown-up/blob/main/LICENSE
|
|
3
3
|
|
|
4
|
+
import {elementModelWrapCallbacks} from './scriptLibrary.js';
|
|
4
5
|
import {executeScriptAsync} from 'bare-script/lib/runtimeAsync.js';
|
|
5
6
|
import {lintScript} from 'bare-script/lib/model.js';
|
|
6
|
-
import {markdownElements} from 'markdown-model/lib/elements.js';
|
|
7
|
-
import {parseMarkdown} from 'markdown-model/lib/parser.js';
|
|
8
7
|
import {parseScript} from 'bare-script/lib/parser.js';
|
|
9
8
|
|
|
10
9
|
|
|
@@ -14,7 +13,6 @@ import {parseScript} from 'bare-script/lib/parser.js';
|
|
|
14
13
|
*
|
|
15
14
|
* @typedef {Object} MarkdownScriptOptions
|
|
16
15
|
* @property {number} fontSize - The font size, in points
|
|
17
|
-
* @property {Object} params - The hash parameters object
|
|
18
16
|
* @property {Object} runtime - The [markdown-script runtime state]{@link module:lib/script.MarkdownScriptRuntime}
|
|
19
17
|
* @property {Object} [variables] - The map of variable name to variable value
|
|
20
18
|
* @property {Object} window - The web browser window object
|
|
@@ -100,13 +98,6 @@ export async function markdownScriptCodeBlock(codeBlock, options) {
|
|
|
100
98
|
}
|
|
101
99
|
|
|
102
100
|
|
|
103
|
-
// Constants
|
|
104
|
-
const defaultDrawingWidth = 300;
|
|
105
|
-
const defaultDrawingHeight = 200;
|
|
106
|
-
const defaultFontFamily = 'Arial, Helvetica, sans-serif';
|
|
107
|
-
const pixelsPerPoint = 4 / 3;
|
|
108
|
-
|
|
109
|
-
|
|
110
101
|
/**
|
|
111
102
|
* The markdown-script runtime state
|
|
112
103
|
*
|
|
@@ -137,27 +128,7 @@ export class MarkdownScriptRuntime {
|
|
|
137
128
|
this.windowResize = null;
|
|
138
129
|
this.windowTimeout = null;
|
|
139
130
|
this.eventQueue = Promise.resolve();
|
|
140
|
-
|
|
141
|
-
// Drawing-path and Markdown function state
|
|
142
|
-
this.drawingPath = null;
|
|
143
131
|
this.markdown = null;
|
|
144
|
-
|
|
145
|
-
// Drawing state
|
|
146
|
-
this.drawingWidth = defaultDrawingWidth;
|
|
147
|
-
this.drawingHeight = defaultDrawingHeight;
|
|
148
|
-
|
|
149
|
-
// Drawing path style
|
|
150
|
-
this.drawingPathStroke = 'black';
|
|
151
|
-
this.drawingPathStrokeWidth = 1;
|
|
152
|
-
this.drawingPathStrokeDashArray = 'none';
|
|
153
|
-
this.drawingPathFill = 'none';
|
|
154
|
-
|
|
155
|
-
// Drawing text style
|
|
156
|
-
this.drawingFontFamily = defaultFontFamily;
|
|
157
|
-
this.drawingFontSizePx = options.fontSize * pixelsPerPoint;
|
|
158
|
-
this.drawingFontFill = 'black';
|
|
159
|
-
this.drawingFontBold = false;
|
|
160
|
-
this.drawingFontItalic = false;
|
|
161
132
|
}
|
|
162
133
|
|
|
163
134
|
|
|
@@ -198,7 +169,6 @@ export class MarkdownScriptRuntime {
|
|
|
198
169
|
if (this.elements === null) {
|
|
199
170
|
this.elements = [];
|
|
200
171
|
}
|
|
201
|
-
this.finishDrawingPath();
|
|
202
172
|
this.finishMarkdown();
|
|
203
173
|
}
|
|
204
174
|
|
|
@@ -209,64 +179,6 @@ export class MarkdownScriptRuntime {
|
|
|
209
179
|
}
|
|
210
180
|
|
|
211
181
|
|
|
212
|
-
// Helper method to start an SVG drawing
|
|
213
|
-
setDrawing(newDrawing = false) {
|
|
214
|
-
this.setElements();
|
|
215
|
-
let svg = this.getDrawingSVG();
|
|
216
|
-
if (svg === null || newDrawing) {
|
|
217
|
-
svg = {
|
|
218
|
-
'svg': 'svg',
|
|
219
|
-
'attr': {
|
|
220
|
-
'width': this.drawingWidth,
|
|
221
|
-
'height': this.drawingHeight
|
|
222
|
-
},
|
|
223
|
-
'elem': []
|
|
224
|
-
};
|
|
225
|
-
this.elements.push({'html': 'p', 'elem': svg});
|
|
226
|
-
}
|
|
227
|
-
return svg;
|
|
228
|
-
}
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
// Helper method to get the current SVG drawing element
|
|
232
|
-
getDrawingSVG() {
|
|
233
|
-
const par = (this.elements.length !== 0 ? this.elements[this.elements.length - 1] : null);
|
|
234
|
-
const svg = (par !== null && par.html === 'p' && 'elem' in par ? par.elem : null);
|
|
235
|
-
return svg !== null && svg.svg === 'svg' ? svg : null;
|
|
236
|
-
}
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
// Helper method to start an SVG drawing path
|
|
240
|
-
setDrawingPath() {
|
|
241
|
-
if (this.drawingPath === null) {
|
|
242
|
-
const svg = this.setDrawing();
|
|
243
|
-
svg.elem.push({
|
|
244
|
-
'svg': 'path',
|
|
245
|
-
'attr': {
|
|
246
|
-
'fill': this.drawingPathFill,
|
|
247
|
-
'stroke': this.drawingPathStroke,
|
|
248
|
-
'stroke-width': this.drawingPathStrokeWidth,
|
|
249
|
-
'stroke-dasharray': this.drawingPathStrokeDashArray,
|
|
250
|
-
'd': ''
|
|
251
|
-
}
|
|
252
|
-
});
|
|
253
|
-
this.drawingPath = [];
|
|
254
|
-
}
|
|
255
|
-
}
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
// Helper method to finish the current SVG drawing path
|
|
259
|
-
finishDrawingPath() {
|
|
260
|
-
if (this.drawingPath !== null) {
|
|
261
|
-
const svg = this.getDrawingSVG();
|
|
262
|
-
const path = svg.elem[svg.elem.length - 1];
|
|
263
|
-
// eslint-disable-next-line id-length
|
|
264
|
-
path.attr.d = this.drawingPath.join(' ');
|
|
265
|
-
this.drawingPath = null;
|
|
266
|
-
}
|
|
267
|
-
}
|
|
268
|
-
|
|
269
|
-
|
|
270
182
|
// Helper method to start a Markdown block
|
|
271
183
|
setMarkdown() {
|
|
272
184
|
if (this.markdown === null) {
|
|
@@ -285,11 +197,12 @@ export class MarkdownScriptRuntime {
|
|
|
285
197
|
// Helper method to finish the current Markdown block and add its elements
|
|
286
198
|
finishMarkdown() {
|
|
287
199
|
if (this.markdown !== null) {
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
200
|
+
const markdownElements =
|
|
201
|
+
(markdown, markdownOptions) => this.options.globals.markdownElements([markdown, markdownOptions], this.options);
|
|
202
|
+
const parseMarkdown = (text) => this.options.globals.markdownParse([text], this.options);
|
|
203
|
+
const contentElements = markdownElements(parseMarkdown(this.markdown), this.options.markdownOptions);
|
|
204
|
+
elementModelWrapCallbacks(contentElements, this.options);
|
|
205
|
+
this.addElements(contentElements);
|
|
293
206
|
this.markdown = null;
|
|
294
207
|
}
|
|
295
208
|
}
|