markdown-up 4.2.0 → 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 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 {validateType} from 'schema-markdown/lib/schema.js';
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 = parseSchemaMarkdown(`\
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 && jsonStringifySortKeys(paramsPrev) === jsonStringifySortKeys(this.params)) {
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 = validateType(
285
+ this.params = schemaValidate(
292
286
  markdownUpTypes,
293
287
  'MarkdownUp',
294
- decodeQueryString(paramString ?? this.window.location.hash.slice(1))
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 = validateType(markdownUpTypes, 'MarkdownUpLocal', JSON.parse(localJSON));
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 = validateType(markdownUpTypes, 'MarkdownUpSession', JSON.parse(sessionJSON));
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 = parseMarkdown(markdownText);
428
- const markdownTitle = getMarkdownTitle(markdownModel);
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': markdownTitle,
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': markdownTitle,
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 = decodeQueryString(url.slice(1));
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 = encodeQueryString({...this.params, ...hashParams});
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 = encodeQueryString(this.params);
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 = `#${encodeQueryString(params)}`;
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/model.js';
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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "type": "module",
3
3
  "name": "markdown-up",
4
- "version": "4.2.0",
4
+ "version": "5.0.0",
5
5
  "description": "MarkdownUp is a Markdown viewer",
6
6
  "keywords": [
7
7
  "markdown",
@@ -22,9 +22,8 @@
22
22
  "test": "node --test test/"
23
23
  },
24
24
  "dependencies": {
25
- "bare-script": "~4.2",
26
- "element-model": "~1.2",
27
- "schema-markdown": "~1.3"
25
+ "bare-script": "~5.0",
26
+ "element-model": "~1.2"
28
27
  },
29
28
  "devDependencies": {
30
29
  "@eslint/js": "~10.0",