markdown-up 4.1.1 → 5.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/lib/app.js +19 -51
- package/lib/appImports.js +3 -7
- package/lib/script.js +3 -5
- package/lib/scriptLibrary.js +1 -0
- package/package.json +5 -6
package/lib/app.js
CHANGED
|
@@ -4,18 +4,18 @@
|
|
|
4
4
|
/** @module lib/app */
|
|
5
5
|
|
|
6
6
|
import {MarkdownScriptRuntime, markdownScriptCodeBlock} from './script.js';
|
|
7
|
-
import {decodeQueryString, encodeQueryString, jsonStringifySortKeys} from 'schema-markdown/lib/encode.js';
|
|
8
7
|
import {elementModelWrapCallbacks, markdownScriptFunctions} from './scriptLibrary.js';
|
|
8
|
+
import {markdownElementsAsync, markdownParse, markdownTitle, schemaParse, schemaValidate} from 'bare-script/lib/include.js';
|
|
9
|
+
// eslint-disable-next-line no-duplicate-imports
|
|
10
|
+
import {urlDecodeQueryString, urlEncodeQueryString} from 'bare-script/lib/include.js';
|
|
9
11
|
import {evaluateExpression} from 'bare-script/lib/runtime.js';
|
|
10
|
-
import {executeScriptAsync} from 'bare-script/lib/runtimeAsync.js';
|
|
11
12
|
import {parseExpression} from 'bare-script/lib/parser.js';
|
|
12
|
-
import {parseSchemaMarkdown} from 'schema-markdown/lib/parser.js';
|
|
13
13
|
import {renderElements} from 'element-model/lib/elementModel.js';
|
|
14
|
-
import {
|
|
14
|
+
import {valueJSON} from 'bare-script/lib/value.js';
|
|
15
15
|
|
|
16
16
|
|
|
17
17
|
// The application's hash parameter type model
|
|
18
|
-
const markdownUpTypes =
|
|
18
|
+
const markdownUpTypes = schemaParse(`\
|
|
19
19
|
# The MarkdownUp hash parameters
|
|
20
20
|
struct MarkdownUp
|
|
21
21
|
|
|
@@ -74,15 +74,10 @@ enum MarkdownUpView
|
|
|
74
74
|
* @property {?number} [lineHeight = 1.3] - The line height, in em
|
|
75
75
|
* @property {?string} [markdownText = null] - The default Markdown text
|
|
76
76
|
* @property {?boolean} [menu = true] - If true, show the menu
|
|
77
|
-
* @property {?string} [systemPrefix] - The markdown-script system include prefix
|
|
78
77
|
* @property {?string} [url = 'README.md'] - The default resource URL
|
|
79
78
|
*/
|
|
80
79
|
|
|
81
80
|
|
|
82
|
-
// The default system include path prefix
|
|
83
|
-
const defaultSystemPrefix = 'https://craigahobbs.github.io/markdown-up/include/';
|
|
84
|
-
|
|
85
|
-
|
|
86
81
|
// The default application help URL
|
|
87
82
|
const defaultHelpURL = 'https://craigahobbs.github.io/markdown-up-py/';
|
|
88
83
|
|
|
@@ -111,7 +106,6 @@ export class MarkdownUp {
|
|
|
111
106
|
this.lineHeight = (options !== null ? options.lineHeight : null) ?? 1.3;
|
|
112
107
|
this.markdownText = (options !== null ? options.markdownText : null) ?? null;
|
|
113
108
|
this.menu = (options !== null ? options.menu : null) ?? true;
|
|
114
|
-
this.systemPrefix = (options !== null ? options.systemPrefix : null) ?? defaultSystemPrefix;
|
|
115
109
|
this.url = (options !== null ? options.url : null) ?? 'README.md';
|
|
116
110
|
this.runtimeDocumentKeyDown = null;
|
|
117
111
|
this.runtimeWindowResize = null;
|
|
@@ -189,7 +183,7 @@ export class MarkdownUp {
|
|
|
189
183
|
this.updateParams();
|
|
190
184
|
|
|
191
185
|
// Skip the render if the page params haven't changed
|
|
192
|
-
if (!forceRender && paramsPrev !== null &&
|
|
186
|
+
if (!forceRender && paramsPrev !== null && valueJSON(paramsPrev) === valueJSON(this.params)) {
|
|
193
187
|
return;
|
|
194
188
|
}
|
|
195
189
|
} catch ({message}) {
|
|
@@ -288,17 +282,17 @@ export class MarkdownUp {
|
|
|
288
282
|
this.paramsSession = {};
|
|
289
283
|
|
|
290
284
|
// Decode and validate the hash parameters
|
|
291
|
-
this.params =
|
|
285
|
+
this.params = schemaValidate(
|
|
292
286
|
markdownUpTypes,
|
|
293
287
|
'MarkdownUp',
|
|
294
|
-
|
|
288
|
+
urlDecodeQueryString(paramString ?? this.window.location.hash.slice(1))
|
|
295
289
|
);
|
|
296
290
|
|
|
297
291
|
// Decode and validate the local storage paramters
|
|
298
292
|
const localJSON = localJSONString ?? this.window.localStorage.getItem('MarkdownUp');
|
|
299
293
|
if (localJSON !== null) {
|
|
300
294
|
try {
|
|
301
|
-
this.paramsLocal =
|
|
295
|
+
this.paramsLocal = schemaValidate(markdownUpTypes, 'MarkdownUpLocal', JSON.parse(localJSON));
|
|
302
296
|
} catch {
|
|
303
297
|
// Do nothing
|
|
304
298
|
}
|
|
@@ -308,7 +302,7 @@ export class MarkdownUp {
|
|
|
308
302
|
const sessionJSON = sessionJSONString ?? this.window.sessionStorage.getItem('MarkdownUp');
|
|
309
303
|
if (sessionJSON !== null) {
|
|
310
304
|
try {
|
|
311
|
-
this.paramsSession =
|
|
305
|
+
this.paramsSession = schemaValidate(markdownUpTypes, 'MarkdownUpSession', JSON.parse(sessionJSON));
|
|
312
306
|
} catch {
|
|
313
307
|
// Do nothing
|
|
314
308
|
}
|
|
@@ -353,30 +347,6 @@ export class MarkdownUp {
|
|
|
353
347
|
const url = this.getResourceURL();
|
|
354
348
|
const scriptOptions = this.createScriptOptions();
|
|
355
349
|
|
|
356
|
-
// Load BareScript
|
|
357
|
-
const includeScript = {
|
|
358
|
-
'statements': [
|
|
359
|
-
{
|
|
360
|
-
'include': {
|
|
361
|
-
'includes': [
|
|
362
|
-
{'url': 'markdown.bare', 'system': true},
|
|
363
|
-
{'url': 'markdownHighlight.bare', 'system': true},
|
|
364
|
-
{'url': 'markdownElements.bare', 'system': true},
|
|
365
|
-
{'url': 'markdownParser.bare', 'system': true},
|
|
366
|
-
|
|
367
|
-
// Additional common includes
|
|
368
|
-
{'url': 'args.bare', 'system': true}
|
|
369
|
-
]
|
|
370
|
-
}
|
|
371
|
-
}
|
|
372
|
-
]
|
|
373
|
-
};
|
|
374
|
-
await executeScriptAsync(includeScript, scriptOptions);
|
|
375
|
-
const getMarkdownTitle = (markdown) => scriptOptions.globals.markdownTitle([markdown], scriptOptions);
|
|
376
|
-
const markdownElementsAsync =
|
|
377
|
-
(markdown, markdownOptions) => scriptOptions.globals.markdownElementsAsync([markdown, markdownOptions], scriptOptions);
|
|
378
|
-
const parseMarkdown = (text) => scriptOptions.globals.markdownParse([text], scriptOptions);
|
|
379
|
-
|
|
380
350
|
// Get the Markdown text
|
|
381
351
|
let markdownText;
|
|
382
352
|
let timeBegin;
|
|
@@ -424,13 +394,13 @@ export class MarkdownUp {
|
|
|
424
394
|
}
|
|
425
395
|
|
|
426
396
|
// Parse the Markdown and get the title
|
|
427
|
-
const markdownModel =
|
|
428
|
-
const
|
|
397
|
+
const markdownModel = markdownParse(markdownText);
|
|
398
|
+
const title = markdownTitle(markdownModel);
|
|
429
399
|
|
|
430
400
|
// Display the Markdown?
|
|
431
401
|
if (this.params.view === 'markdown') {
|
|
432
402
|
return {
|
|
433
|
-
'title':
|
|
403
|
+
'title': title,
|
|
434
404
|
'elements': [
|
|
435
405
|
this.burgerElements(),
|
|
436
406
|
{'html': 'div', 'attr': {'class': 'markdown'}, 'elem': {'text': markdownText}}
|
|
@@ -441,14 +411,13 @@ export class MarkdownUp {
|
|
|
441
411
|
// Copy the markdown options and override the markdown-script code block renderer
|
|
442
412
|
const scriptMarkdownOptions = {...scriptOptions.markdownOptions};
|
|
443
413
|
scriptMarkdownOptions.codeBlocks = {...scriptMarkdownOptions.codeBlocks};
|
|
444
|
-
scriptMarkdownOptions.codeBlocks['markdown-script'] =
|
|
445
|
-
([codeBlock], fnScriptOptions) => markdownScriptCodeBlock(codeBlock, fnScriptOptions);
|
|
414
|
+
scriptMarkdownOptions.codeBlocks['markdown-script'] = ([codeBlock]) => markdownScriptCodeBlock(codeBlock, scriptOptions);
|
|
446
415
|
|
|
447
416
|
// Render the Markdown
|
|
448
417
|
const contentElements = await markdownElementsAsync(markdownModel, scriptMarkdownOptions);
|
|
449
418
|
elementModelWrapCallbacks(contentElements, scriptOptions);
|
|
450
419
|
const result = {
|
|
451
|
-
'title':
|
|
420
|
+
'title': title,
|
|
452
421
|
'elements': [
|
|
453
422
|
// Menu "burger"
|
|
454
423
|
this.burgerElements(),
|
|
@@ -524,7 +493,6 @@ export class MarkdownUp {
|
|
|
524
493
|
logFn,
|
|
525
494
|
markdownOptions,
|
|
526
495
|
'params': this.params,
|
|
527
|
-
'systemPrefix': this.systemPrefix,
|
|
528
496
|
'urlFn': (url) => this.modifyURL(url),
|
|
529
497
|
'window': this.window
|
|
530
498
|
};
|
|
@@ -609,13 +577,13 @@ export class MarkdownUp {
|
|
|
609
577
|
// Hash URL?
|
|
610
578
|
if (url.startsWith('#')) {
|
|
611
579
|
// Fixup the "url" param if its relative
|
|
612
|
-
const hashParams =
|
|
580
|
+
const hashParams = urlDecodeQueryString(url.slice(1)) ?? {};
|
|
613
581
|
if ('url' in hashParams && hashParams.url !== '' && isRelativeURL(hashParams.url)) {
|
|
614
582
|
hashParams.url = `${getBaseURL(resourceURL)}${hashParams.url}`;
|
|
615
583
|
}
|
|
616
584
|
|
|
617
585
|
// Encode hash parameters with a header ID
|
|
618
|
-
const paramString =
|
|
586
|
+
const paramString = urlEncodeQueryString({...this.params, ...hashParams});
|
|
619
587
|
const headerId = getHeaderId(url);
|
|
620
588
|
return `#${paramString}${headerId !== null && paramString !== '' ? '&' : ''}${headerId !== null ? headerId : ''}`;
|
|
621
589
|
}
|
|
@@ -630,7 +598,7 @@ export class MarkdownUp {
|
|
|
630
598
|
|
|
631
599
|
|
|
632
600
|
burgerElements() {
|
|
633
|
-
const paramString =
|
|
601
|
+
const paramString = urlEncodeQueryString(this.params);
|
|
634
602
|
const topHeaderId = `${paramString}${paramString !== '' ? '&' : ''}_top`;
|
|
635
603
|
return [
|
|
636
604
|
!this.menu ? null : [
|
|
@@ -717,7 +685,7 @@ export class MarkdownUp {
|
|
|
717
685
|
} else {
|
|
718
686
|
params.view = viewValue;
|
|
719
687
|
}
|
|
720
|
-
this.window.location.href = `#${
|
|
688
|
+
this.window.location.href = `#${urlEncodeQueryString(params)}`;
|
|
721
689
|
},
|
|
722
690
|
icon
|
|
723
691
|
);
|
package/lib/appImports.js
CHANGED
|
@@ -5,7 +5,10 @@
|
|
|
5
5
|
// Bulk-import JavaScript
|
|
6
6
|
|
|
7
7
|
// bare-script
|
|
8
|
+
import 'bare-script/lib/include.js';
|
|
9
|
+
import 'bare-script/lib/includeSource.js';
|
|
8
10
|
import 'bare-script/lib/library.js';
|
|
11
|
+
import 'bare-script/lib/lint.js';
|
|
9
12
|
import 'bare-script/lib/model.js';
|
|
10
13
|
import 'bare-script/lib/options.js';
|
|
11
14
|
import 'bare-script/lib/parser.js';
|
|
@@ -20,10 +23,3 @@ import 'element-model/lib/elementModel.js';
|
|
|
20
23
|
export {MarkdownUp} from './app.js';
|
|
21
24
|
import './script.js';
|
|
22
25
|
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,9 +1,10 @@
|
|
|
1
1
|
// Licensed under the MIT License
|
|
2
2
|
// https://github.com/craigahobbs/markdown-up/blob/main/LICENSE
|
|
3
3
|
|
|
4
|
+
import {markdownElements, markdownParse} from 'bare-script/lib/include.js';
|
|
4
5
|
import {elementModelWrapCallbacks} from './scriptLibrary.js';
|
|
5
6
|
import {executeScriptAsync} from 'bare-script/lib/runtimeAsync.js';
|
|
6
|
-
import {lintScript} from 'bare-script/lib/
|
|
7
|
+
import {lintScript} from 'bare-script/lib/lint.js';
|
|
7
8
|
import {parseScript} from 'bare-script/lib/parser.js';
|
|
8
9
|
|
|
9
10
|
|
|
@@ -197,10 +198,7 @@ export class MarkdownScriptRuntime {
|
|
|
197
198
|
// Helper method to finish the current Markdown block and add its elements
|
|
198
199
|
finishMarkdown() {
|
|
199
200
|
if (this.markdown !== null) {
|
|
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);
|
|
201
|
+
const contentElements = markdownElements(markdownParse(this.markdown), this.options.markdownOptions);
|
|
204
202
|
elementModelWrapCallbacks(contentElements, this.options);
|
|
205
203
|
this.addElements(contentElements);
|
|
206
204
|
this.markdown = null;
|
package/lib/scriptLibrary.js
CHANGED
|
@@ -183,6 +183,7 @@ const documentURLArgs = valueArgsModel([
|
|
|
183
183
|
// $doc:
|
|
184
184
|
// $doc: **Note:** Element model "callback" members are a map of event name (e.g., "click") to
|
|
185
185
|
// $doc: event callback function. The following events have callback arguments:
|
|
186
|
+
// $doc: - **click** - For an SVG element, the click's x and y coordinates and the SVG's width and height
|
|
186
187
|
// $doc: - **keydown** - keyCode
|
|
187
188
|
// $doc: - **keypress** - keyCode
|
|
188
189
|
// $doc: - **keyup** - keyCode
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"type": "module",
|
|
3
3
|
"name": "markdown-up",
|
|
4
|
-
"version": "
|
|
4
|
+
"version": "5.0.0",
|
|
5
5
|
"description": "MarkdownUp is a Markdown viewer",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"markdown",
|
|
@@ -22,15 +22,14 @@
|
|
|
22
22
|
"test": "node --test test/"
|
|
23
23
|
},
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"bare-script": "~
|
|
26
|
-
"element-model": "~1.2"
|
|
27
|
-
"schema-markdown": "~1.2"
|
|
25
|
+
"bare-script": "~5.0",
|
|
26
|
+
"element-model": "~1.2"
|
|
28
27
|
},
|
|
29
28
|
"devDependencies": {
|
|
30
29
|
"@eslint/js": "~10.0",
|
|
31
30
|
"c8": "~11.0",
|
|
32
|
-
"eslint": "~10.
|
|
33
|
-
"globals": "~17.
|
|
31
|
+
"eslint": "~10.6",
|
|
32
|
+
"globals": "~17.7",
|
|
34
33
|
"jsdoc": "~4.0",
|
|
35
34
|
"jsdom": "~29.1"
|
|
36
35
|
}
|