markdown-up 1.8.7 → 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/lib/app.js CHANGED
@@ -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
  }
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
 
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "type": "module",
3
3
  "name": "markdown-up",
4
- "version": "1.8.7",
4
+ "version": "1.8.8",
5
5
  "description": "MarkdownUp is a Markdown viewer",
6
6
  "keywords": [
7
7
  "markdown",
@@ -29,9 +29,9 @@
29
29
  "schema-markdown-doc": "~1.5"
30
30
  },
31
31
  "devDependencies": {
32
- "ava": "~5.0",
32
+ "ava": "~5.1",
33
33
  "c8": "~7.12",
34
- "eslint": "~8.27",
34
+ "eslint": "~8.28",
35
35
  "jsdoc": "~4.0",
36
36
  "jsdom": "~20.0"
37
37
  }