markdown-up 1.8.6 → 1.8.8

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 CHANGED
@@ -66,17 +66,19 @@ parse CSV, render data tables, draw line charts, and more. For more information,
66
66
  For example:
67
67
 
68
68
  ```
69
- # MarkdownUp Dynamic Markdown Example
69
+ # Dynamic Markdown Example
70
70
 
71
71
  ~~~ markdown-script
72
72
  # Variable arguments
73
- helloCount = if(vCount != null, vCount, 5)
73
+ helloCount = if(vCount != null, vCount, 3)
74
74
 
75
75
  # Constants
76
- width = 140
77
- height = 40
76
+ width = 200
77
+ height = 60
78
78
  borderSize = 5
79
- borderColor = 'blue'
79
+ borderColor = 'red'
80
+ fillColor = 'blue'
81
+ textColor = 'white'
80
82
 
81
83
  # Render the more/less menu
82
84
  markdownPrint( \
@@ -94,9 +96,9 @@ helloLoop:
94
96
 
95
97
  # Render the hello drawing
96
98
  setDrawingSize(width, height)
97
- drawStyle(borderColor, borderSize)
99
+ drawStyle(borderColor, borderSize, fillColor)
98
100
  drawRect(0.5 * borderSize, 0.5 * borderSize, width - borderSize, height - borderSize)
99
- drawTextStyle(0.67 * height, null, true)
101
+ drawTextStyle(0.67 * height, textColor, true)
100
102
  drawText(helloTitle, 0.5 * width, 0.55 * height)
101
103
 
102
104
  ixHello = ixHello + 1
package/lib/app.js CHANGED
@@ -5,9 +5,9 @@
5
5
 
6
6
  import {MarkdownScriptRuntime, markdownScriptCodeBlock} from './script.js';
7
7
  import {decodeQueryString, encodeQueryString} from 'schema-markdown/lib/encode.js';
8
- import {getBaseURL, isRelativeURL, markdownElementsAsync} from 'markdown-model/lib/elements.js';
9
8
  import {getMarkdownTitle, parseMarkdown} from 'markdown-model/lib/parser.js';
10
9
  import {evaluateExpression} from 'calc-script/lib/runtime.js';
10
+ import {markdownElementsAsync} from 'markdown-model/lib/elements.js';
11
11
  import {markdownScriptFunctions} from './scriptLibrary.js';
12
12
  import {parseExpression} from 'calc-script/lib/parser.js';
13
13
  import {parseSchemaMarkdown} from 'schema-markdown/lib/parser.js';
@@ -19,7 +19,7 @@ import {validateType} from 'schema-markdown/lib/schema.js';
19
19
  // The application's hash parameter type model
20
20
  const markdownUpTypes = parseSchemaMarkdown(`\
21
21
  #
22
- # [MarkdownUp](https://craigahobbs.github.io/markdown-up/) is a Markdown viewer.
22
+ # [MarkdownUp](https://github.com/craigahobbs/markdown-up#readme) is a Markdown viewer.
23
23
  #
24
24
  # ## Hash Parameters
25
25
  #
@@ -142,12 +142,6 @@ export class MarkdownUp {
142
142
  isError = true;
143
143
  }
144
144
 
145
- // Call the application main and validate the result
146
- this.clearRuntimeCallbacks();
147
- if (!isError) {
148
- result = await this.main();
149
- }
150
-
151
145
  // Set the colors
152
146
  const isDarkMode = this.paramsLocal.darkMode ?? this.darkMode;
153
147
  this.window.document.documentElement.style.setProperty('--markdown-model-dark-mode', isDarkMode ? '1' : '0');
@@ -160,6 +154,12 @@ export class MarkdownUp {
160
154
  const lineHeight = this.paramsLocal.lineHeight ?? this.lineHeight;
161
155
  this.window.document.documentElement.style.setProperty('--markdown-model-line-height', `${lineHeight}em`);
162
156
 
157
+ // Call the application main and validate the result
158
+ this.clearRuntimeCallbacks();
159
+ if (!isError) {
160
+ result = await this.main();
161
+ }
162
+
163
163
  // Set the window title
164
164
  const title = result.title ?? null;
165
165
  if (title !== null) {
@@ -277,10 +277,30 @@ export class MarkdownUp {
277
277
  // Get the Markdown text
278
278
  const urlOverride = 'url' in this.params && this.params.url !== '';
279
279
  const url = urlOverride ? this.params.url : this.url;
280
+ const scriptOptions = this.createScriptOptions(url);
280
281
  let markdownText = null;
282
+ let timeBegin;
281
283
  if (this.markdownText !== null && !urlOverride) {
282
284
  ({markdownText} = this);
285
+
286
+ // Log Markdown render begin
287
+ if ('logFn' in scriptOptions) {
288
+ timeBegin = performance.now();
289
+ scriptOptions.logFn('MarkdownUp: ===== Rendering Markdown text');
290
+ }
283
291
  } else {
292
+ // Log Markdown render begin
293
+ if ('logFn' in scriptOptions) {
294
+ scriptOptions.logFn(`MarkdownUp: ===== Rendering Markdown document "${url}"`);
295
+ }
296
+
297
+ // Log Markdown fetch begin
298
+ let fetchBegin;
299
+ if ('logFn' in scriptOptions) {
300
+ fetchBegin = performance.now();
301
+ scriptOptions.logFn(`MarkdownUp: Fetching "${url}" ...`);
302
+ }
303
+
284
304
  // Fetch the Markdown text resource URL
285
305
  const response = await this.window.fetch(url);
286
306
  if (!response.ok) {
@@ -294,6 +314,13 @@ export class MarkdownUp {
294
314
  };
295
315
  }
296
316
  markdownText = await response.text();
317
+
318
+ // Log Markdown fetch end with timing
319
+ if ('logFn' in scriptOptions) {
320
+ const fetchEnd = performance.now();
321
+ timeBegin = performance.now();
322
+ scriptOptions.logFn(`MarkdownUp: Fetch completed in ${(fetchEnd - fetchBegin).toFixed(1)} milliseconds`);
323
+ }
297
324
  }
298
325
 
299
326
  // Parse the Markdown and get the title
@@ -312,7 +339,6 @@ export class MarkdownUp {
312
339
  }
313
340
 
314
341
  // Render the Markdown
315
- const scriptOptions = this.createScriptOptions(url);
316
342
  const result = {
317
343
  'title': markdownTitle,
318
344
  'elements': [
@@ -354,6 +380,12 @@ export class MarkdownUp {
354
380
  // Reset the runtime
355
381
  scriptOptions.runtime.reset();
356
382
 
383
+ // Log Markdown render end
384
+ if ('logFn' in scriptOptions) {
385
+ const timeEnd = performance.now();
386
+ scriptOptions.logFn(`MarkdownUp: Markdown rendered in ${(timeEnd - timeBegin).toFixed(1)} milliseconds`);
387
+ }
388
+
357
389
  return result;
358
390
  }
359
391
 
@@ -386,7 +418,7 @@ export class MarkdownUp {
386
418
  scriptOptions.variables[varName] = evaluateExpression(parseExpression(varExprStr), scriptOptions.variables);
387
419
  } catch ({message}) {
388
420
  if (logFn !== null) {
389
- logFn(`Error evaluating variable "${varName}" expression "${varExprStr}": ${message}`);
421
+ logFn(`MarkdownUp: Error evaluating variable "${varName}" expression "${varExprStr}": ${message}`);
390
422
  }
391
423
  }
392
424
  }
@@ -610,3 +642,17 @@ function getHashID(url) {
610
642
  }
611
643
 
612
644
  const rHashId = /[#&]([^=]+)$/;
645
+
646
+
647
+ // Test if a URL is relative
648
+ function isRelativeURL(url) {
649
+ return !rNotRelativeURL.test(url);
650
+ }
651
+
652
+ const rNotRelativeURL = /^(?:[a-z]+:|\/|\?|#)/;
653
+
654
+
655
+ // Get a URL's base URL
656
+ function getBaseURL(url) {
657
+ return url.slice(0, url.lastIndexOf('/') + 1);
658
+ }
package/lib/script.js CHANGED
@@ -49,6 +49,13 @@ export async function markdownScriptCodeBlock(codeBlock, options) {
49
49
  Object.assign(options.globals, options.variables);
50
50
  }
51
51
 
52
+ // Log script execution begin
53
+ let timeBegin;
54
+ if ('logFn' in options) {
55
+ timeBegin = performance.now();
56
+ options.logFn(`MarkdownUp: Executing script at line number ${codeBlock.startLineNumber + 1} ...`);
57
+ }
58
+
52
59
  // Execute the calculation script
53
60
  let errorMessage = null;
54
61
  try {
@@ -58,10 +65,12 @@ export async function markdownScriptCodeBlock(codeBlock, options) {
58
65
  // Run the calc-script linter?
59
66
  if ('logFn' in options) {
60
67
  const warnings = lintScript(script);
61
- if (warnings.length > 0) {
62
- options.logFn(`Warnings for the script at line number ${codeBlock.startLineNumber + 1}:`);
68
+ if (warnings.length === 0) {
69
+ options.logFn(`MarkdownUp: Script static analysis... OK`);
70
+ } else {
71
+ options.logFn(`MarkdownUp: Script static analysis ... ${warnings.length} warning${warnings.length > 1 ? 's' : ''}:`);
63
72
  for (const warning of warnings) {
64
- options.logFn(` ${warning}`);
73
+ options.logFn(`MarkdownUp: ${warning}`);
65
74
  }
66
75
  }
67
76
  }
@@ -72,6 +81,12 @@ export async function markdownScriptCodeBlock(codeBlock, options) {
72
81
  errorMessage = message;
73
82
  }
74
83
 
84
+ // Log script execution end with timing
85
+ if ('logFn' in options) {
86
+ const timeEnd = performance.now();
87
+ options.logFn(`MarkdownUp: Script executed in ${(timeEnd - timeBegin).toFixed(1)} milliseconds`);
88
+ }
89
+
75
90
  // Reset the runtime
76
91
  let elements = options.runtime.resetElements();
77
92
 
@@ -259,7 +274,11 @@ export class MarkdownScriptRuntime {
259
274
  finishMarkdown() {
260
275
  if (this.markdown !== null) {
261
276
  const markdownOptions = {'headerIds': true, 'urlFn': this.options.urlFn};
262
- this.addElements(markdownElements(parseMarkdown(this.markdown), markdownOptions));
277
+ try {
278
+ this.addElements(markdownElements(parseMarkdown(this.markdown), markdownOptions));
279
+ } catch {
280
+ // Do nothing
281
+ }
263
282
  this.markdown = null;
264
283
  }
265
284
  }
@@ -5,10 +5,10 @@ import {
5
5
  addCalculatedField, aggregateData, filterData, joinData, parseCSV, sortData, topData, validateAggregation, validateData
6
6
  } from './data.js';
7
7
  import {dataTableElements, validateDataTable} from './dataTable.js';
8
- import {escapeMarkdownText, markdownHeaderId} from 'markdown-model/lib/elements.js';
9
- import {getMarkdownTitle, parseMarkdown} from 'markdown-model/lib/parser.js';
8
+ import {escapeMarkdownText, getMarkdownTitle, parseMarkdown} from 'markdown-model/lib/parser.js';
10
9
  import {lineChartElements, validateLineChart} from './lineChart.js';
11
10
  import {encodeQueryString} from 'schema-markdown/lib/encode.js';
11
+ import {markdownHeaderId} from 'markdown-model/lib/elements.js';
12
12
  import {schemaMarkdownDoc} from 'schema-markdown-doc/lib/schemaMarkdownDoc.js';
13
13
  import {validateElements} from 'element-model/lib/elementModel.js';
14
14
 
@@ -647,7 +647,8 @@ export const markdownScriptFunctions = {
647
647
 
648
648
  // $function: schemaElements
649
649
  // $group: Schema
650
- // $doc: Render a schema type's documentation
650
+ // $doc: Get a schema type's documentation [element model](https://github.com/craigahobbs/element-model#readme).
651
+ // $doc: Render the element model with the [elementModelRender](#var.vName='elementModelRender') function.
651
652
  // $arg types: The [type model](https://craigahobbs.github.io/schema-markdown-doc/doc/#var.vName='Types')
652
653
  // $arg typeName: The type name
653
654
  // $arg actionURLs: Optional (default is null). The
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "type": "module",
3
3
  "name": "markdown-up",
4
- "version": "1.8.6",
4
+ "version": "1.8.8",
5
5
  "description": "MarkdownUp is a Markdown viewer",
6
6
  "keywords": [
7
7
  "markdown",
@@ -24,15 +24,15 @@
24
24
  "dependencies": {
25
25
  "calc-script": "~1.3",
26
26
  "element-model": "~1.1",
27
- "markdown-model": "~1.6",
27
+ "markdown-model": "~1.7",
28
28
  "schema-markdown": "~1.2",
29
29
  "schema-markdown-doc": "~1.5"
30
30
  },
31
31
  "devDependencies": {
32
- "ava": "~4.3",
32
+ "ava": "~5.1",
33
33
  "c8": "~7.12",
34
- "eslint": "~8.24",
35
- "jsdoc": "~3.6",
34
+ "eslint": "~8.28",
35
+ "jsdoc": "~4.0",
36
36
  "jsdom": "~20.0"
37
37
  }
38
38
  }