markdown-up 1.8.4 → 1.8.6

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
@@ -77,6 +77,7 @@ enum MarkdownUpView
77
77
  * @typedef {Object} MarkdownUpOptions
78
78
  * @property {boolean} [darkMode = false] - If true, use dark mode by default
79
79
  * @property {number} [fontSize = 12] - The font size, in points
80
+ * @property {?Object} [globals = null] - Global script runtime variables
80
81
  * @property {number} [lineHeight = 1.2] - The line height, in em
81
82
  * @property {?string} [markdownText = null] - The default Markdown text
82
83
  * @property {boolean} [menu = true] - If true, show the menu
@@ -101,6 +102,7 @@ export class MarkdownUp {
101
102
  this.paramsSession = null;
102
103
  this.darkMode = (options !== null ? options.darkMode : null) ?? false;
103
104
  this.fontSize = (options !== null ? options.fontSize : null) ?? 12;
105
+ this.globals = (options !== null ? options.globals : null) ?? null;
104
106
  this.lineHeight = (options !== null ? options.lineHeight : null) ?? 1.2;
105
107
  this.markdownText = (options !== null ? options.markdownText : null) ?? null;
106
108
  this.menu = (options !== null ? options.menu : null) ?? true;
@@ -393,6 +395,9 @@ export class MarkdownUp {
393
395
  // Create the markdown-script runtime
394
396
  const runtime = new MarkdownScriptRuntime(scriptOptions);
395
397
  scriptOptions.globals = {...markdownScriptFunctions};
398
+ if (this.globals !== null) {
399
+ Object.assign(scriptOptions.globals, this.globals);
400
+ }
396
401
  scriptOptions.runtime = runtime;
397
402
  scriptOptions.runtimeUpdateFn = () => {
398
403
  // Did script set the document title?
@@ -8,11 +8,8 @@ import {dataTableElements, validateDataTable} from './dataTable.js';
8
8
  import {escapeMarkdownText, markdownHeaderId} from 'markdown-model/lib/elements.js';
9
9
  import {getMarkdownTitle, parseMarkdown} from 'markdown-model/lib/parser.js';
10
10
  import {lineChartElements, validateLineChart} from './lineChart.js';
11
- import {validateType, validateTypeModel} from 'schema-markdown/lib/schema.js';
12
11
  import {encodeQueryString} from 'schema-markdown/lib/encode.js';
13
- import {parseSchemaMarkdown} from 'schema-markdown/lib/parser.js';
14
12
  import {schemaMarkdownDoc} from 'schema-markdown-doc/lib/schemaMarkdownDoc.js';
15
- import {typeModel} from 'schema-markdown/lib/typeModel.js';
16
13
  import {validateElements} from 'element-model/lib/elementModel.js';
17
14
 
18
15
 
@@ -648,54 +645,23 @@ export const markdownScriptFunctions = {
648
645
  // Schema functions
649
646
  //
650
647
 
651
- // $function: schemaParse
652
- // $group: Schema
653
- // $doc: Parse the [Schema Markdown](https://craigahobbs.github.io/schema-markdown/schema-markdown.html) text
654
- // $arg lines: The [Schema Markdown](https://craigahobbs.github.io/schema-markdown/schema-markdown.html)
655
- // $arg lines: text lines (may contain nested arrays of un-split lines)
656
- // $return: The schema's [type model](https://craigahobbs.github.io/schema-markdown-doc/doc/#var.vName='Types')
657
- 'schemaParse': (lines) => parseSchemaMarkdown(lines),
658
-
659
- // $function: schemaPrint
648
+ // $function: schemaElements
660
649
  // $group: Schema
661
650
  // $doc: Render a schema type's documentation
662
651
  // $arg types: The [type model](https://craigahobbs.github.io/schema-markdown-doc/doc/#var.vName='Types')
663
652
  // $arg typeName: The type name
664
653
  // $arg actionURLs: Optional (default is null). The
665
654
  // $arg actionURLs: [action URL overrides](https://craigahobbs.github.io/schema-markdown-doc/doc/#var.vName='ActionURL').
666
- 'schemaPrint': ([types, typeName, actionURLs = null], options) => {
667
- const {runtime} = options;
655
+ // $return: The schema type's documentation [element model](https://github.com/craigahobbs/element-model#readme)
656
+ 'schemaElements': ([types, typeName, actionURLs = null], options) => {
668
657
  const params = encodeQueryString(options.params);
669
658
  const schemaOptions = {params};
670
659
  if (actionURLs !== null) {
671
660
  schemaOptions.actionURLs = actionURLs;
672
661
  }
673
- runtime.setElements();
674
- runtime.addElements(schemaMarkdownDoc(types, typeName, schemaOptions));
662
+ return schemaMarkdownDoc(types, typeName, schemaOptions);
675
663
  },
676
664
 
677
- // $function: schemaTypeModel
678
- // $group: Schema
679
- // $doc: Get the [Schema Markdown Type Model](https://craigahobbs.github.io/schema-markdown-doc/doc/#var.vName='Types')
680
- // $return: The [Schema Markdown Type Model](https://craigahobbs.github.io/schema-markdown-doc/doc/#var.vName='Types')
681
- 'schemaTypeModel': () => typeModel,
682
-
683
- // $function: schemaValidate
684
- // $group: Schema
685
- // $doc: Validate an object to a schema type
686
- // $arg types: The [type model](https://craigahobbs.github.io/schema-markdown-doc/doc/#var.vName='Types')
687
- // $arg typeName: The type name
688
- // $arg value: The object to validate
689
- // $return: The validated object or null if validation fails
690
- 'schemaValidate': ([types, typeName, value]) => validateType(types, typeName, value),
691
-
692
- // $function: schemaValidateTypeModel
693
- // $group: Schema
694
- // $doc: Validate a [Schema Markdown Type Model](https://craigahobbs.github.io/schema-markdown-doc/doc/#var.vName='Types')
695
- // $arg types: The [type model](https://craigahobbs.github.io/schema-markdown-doc/doc/#var.vName='Types') to validate
696
- // $return: The validated [type model](https://craigahobbs.github.io/schema-markdown-doc/doc/#var.vName='Types')
697
- 'schemaValidateTypeModel': ([types]) => validateTypeModel(types),
698
-
699
665
 
700
666
  //
701
667
  // Session storage functions
@@ -734,7 +700,7 @@ function elementModelWrapCallbacks(elements, options) {
734
700
  for (const childElements of elements) {
735
701
  elementModelWrapCallbacks(childElements, options);
736
702
  }
737
- } else if (typeof elements === 'object') {
703
+ } else if (elements !== null && typeof elements === 'object') {
738
704
  if ('elem' in elements) {
739
705
  elementModelWrapCallbacks(elements.elem, options);
740
706
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "type": "module",
3
3
  "name": "markdown-up",
4
- "version": "1.8.4",
4
+ "version": "1.8.6",
5
5
  "description": "MarkdownUp is a Markdown viewer",
6
6
  "keywords": [
7
7
  "markdown",