markdown-up 2.0.0 → 2.0.2
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 +5 -5
- package/lib/app.js +8 -8
- package/lib/data.js +5 -5
- package/lib/script.js +8 -8
- package/lib/scriptLibrary.js +6 -6
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -62,7 +62,7 @@ To view a different Markdown resource, set the application's
|
|
|
62
62
|
Using MarkdownUp's "markdown-script" fenced code blocks, you can dynamically generate Markdown,
|
|
63
63
|
allowing you to build lightweight, client-rendered web applications with no HTML, no CSS, and a
|
|
64
64
|
single dependency (MarkdownUp). The "markdown-script" fenced code blocks are interpreted as the
|
|
65
|
-
[
|
|
65
|
+
[BareScript programming language](https://craigahobbs.github.io/bare-script/language/).
|
|
66
66
|
In addition to generating Markdown, you can fetch text and JSON resources, create SVG drawings,
|
|
67
67
|
parse CSV, render data tables, draw line charts, and more. For more information, see the
|
|
68
68
|
[MarkdownUp Library](https://craigahobbs.github.io/markdown-up/library/).
|
|
@@ -133,14 +133,14 @@ documentation for more information on the available include libraries.
|
|
|
133
133
|
|
|
134
134
|
### Debug Mode
|
|
135
135
|
|
|
136
|
-
Debug mode logs the script runtime duration and runs the
|
|
136
|
+
Debug mode logs the script runtime duration and runs the BareScript linter, which performs static
|
|
137
137
|
code analysis on your code and reports warnings for any issues found.
|
|
138
138
|
|
|
139
139
|
Debug mode also enables debug logging using the
|
|
140
|
-
[consoleLogDebug function](https://craigahobbs.github.io/
|
|
140
|
+
[consoleLogDebug function](https://craigahobbs.github.io/bare-script/library/#var.vName='consoleLogDebug').
|
|
141
141
|
For example:
|
|
142
142
|
|
|
143
|
-
~~~
|
|
143
|
+
~~~ barescript
|
|
144
144
|
consoleLogDebug('Hello debug')
|
|
145
145
|
~~~
|
|
146
146
|
|
|
@@ -150,7 +150,7 @@ To turn on debug mode, click the debug button in the MarkdownUp menu in the uppe
|
|
|
150
150
|
### Links
|
|
151
151
|
|
|
152
152
|
- [MarkdownUp Application Examples](https://craigahobbs.github.io/#url=MarkdownUpApplications.md)
|
|
153
|
-
- [The
|
|
153
|
+
- [The BareScript Language](https://craigahobbs.github.io/bare-script/language/)
|
|
154
154
|
- [The MarkdownUp Library](https://craigahobbs.github.io/markdown-up/library/)
|
|
155
155
|
- [The MarkdownUp Include Library](https://craigahobbs.github.io/markdown-up/library/include.html)
|
|
156
156
|
|
package/lib/app.js
CHANGED
|
@@ -6,10 +6,10 @@
|
|
|
6
6
|
import {MarkdownScriptRuntime, markdownScriptCodeBlock} from './script.js';
|
|
7
7
|
import {decodeQueryString, encodeQueryString, jsonStringifySortKeys} from 'schema-markdown/lib/encode.js';
|
|
8
8
|
import {getMarkdownTitle, parseMarkdown} from 'markdown-model/lib/parser.js';
|
|
9
|
-
import {evaluateExpression} from '
|
|
9
|
+
import {evaluateExpression} from 'bare-script/lib/runtime.js';
|
|
10
10
|
import {markdownElementsAsync} from 'markdown-model/lib/elements.js';
|
|
11
11
|
import {markdownScriptFunctions} from './scriptLibrary.js';
|
|
12
|
-
import {parseExpression} from '
|
|
12
|
+
import {parseExpression} from 'bare-script/lib/parser.js';
|
|
13
13
|
import {parseSchemaMarkdown} from 'schema-markdown/lib/parser.js';
|
|
14
14
|
import {renderElements} from 'element-model/lib/elementModel.js';
|
|
15
15
|
import {schemaMarkdownDoc} from 'schema-markdown-doc/lib/schemaMarkdownDoc.js';
|
|
@@ -286,19 +286,19 @@ export class MarkdownUp {
|
|
|
286
286
|
({markdownText} = this);
|
|
287
287
|
|
|
288
288
|
// Log Markdown render begin
|
|
289
|
-
if ('logFn' in scriptOptions) {
|
|
289
|
+
if ('logFn' in scriptOptions && scriptOptions.debug) {
|
|
290
290
|
timeBegin = performance.now();
|
|
291
291
|
scriptOptions.logFn('MarkdownUp: ===== Rendering Markdown text');
|
|
292
292
|
}
|
|
293
293
|
} else {
|
|
294
294
|
// Log Markdown render begin
|
|
295
|
-
if ('logFn' in scriptOptions) {
|
|
295
|
+
if ('logFn' in scriptOptions && scriptOptions.debug) {
|
|
296
296
|
scriptOptions.logFn(`MarkdownUp: ===== Rendering Markdown document "${url}"`);
|
|
297
297
|
}
|
|
298
298
|
|
|
299
299
|
// Log Markdown fetch begin
|
|
300
300
|
let fetchBegin;
|
|
301
|
-
if ('logFn' in scriptOptions) {
|
|
301
|
+
if ('logFn' in scriptOptions && scriptOptions.debug) {
|
|
302
302
|
fetchBegin = performance.now();
|
|
303
303
|
scriptOptions.logFn(`MarkdownUp: Fetching "${url}" ...`);
|
|
304
304
|
}
|
|
@@ -318,7 +318,7 @@ export class MarkdownUp {
|
|
|
318
318
|
markdownText = await response.text();
|
|
319
319
|
|
|
320
320
|
// Log Markdown fetch end with timing
|
|
321
|
-
if ('logFn' in scriptOptions) {
|
|
321
|
+
if ('logFn' in scriptOptions && scriptOptions.debug) {
|
|
322
322
|
const fetchEnd = performance.now();
|
|
323
323
|
timeBegin = performance.now();
|
|
324
324
|
scriptOptions.logFn(`MarkdownUp: Fetch completed in ${(fetchEnd - fetchBegin).toFixed(1)} milliseconds`);
|
|
@@ -383,7 +383,7 @@ export class MarkdownUp {
|
|
|
383
383
|
scriptOptions.runtime.reset();
|
|
384
384
|
|
|
385
385
|
// Log Markdown render end
|
|
386
|
-
if ('logFn' in scriptOptions) {
|
|
386
|
+
if ('logFn' in scriptOptions && scriptOptions.debug) {
|
|
387
387
|
const timeEnd = performance.now();
|
|
388
388
|
scriptOptions.logFn(`MarkdownUp: Markdown rendered in ${(timeEnd - timeBegin).toFixed(1)} milliseconds`);
|
|
389
389
|
}
|
|
@@ -416,7 +416,7 @@ export class MarkdownUp {
|
|
|
416
416
|
try {
|
|
417
417
|
scriptOptions.variables[varName] = evaluateExpression(parseExpression(varExprStr), scriptOptions.variables);
|
|
418
418
|
} catch ({message}) {
|
|
419
|
-
if (logFn !== null) {
|
|
419
|
+
if (logFn !== null && scriptOptions.debug) {
|
|
420
420
|
logFn(`MarkdownUp: Error evaluating variable "${varName}" expression "${varExprStr}": ${message}`);
|
|
421
421
|
}
|
|
422
422
|
}
|
package/lib/data.js
CHANGED
|
@@ -3,9 +3,9 @@
|
|
|
3
3
|
|
|
4
4
|
/** @module lib/data */
|
|
5
5
|
|
|
6
|
-
import {evaluateExpression} from '
|
|
6
|
+
import {evaluateExpression} from 'bare-script/lib/runtime.js';
|
|
7
7
|
import {jsonStringifySortKeys} from 'schema-markdown/lib/encode.js';
|
|
8
|
-
import {parseExpression} from '
|
|
8
|
+
import {parseExpression} from 'bare-script/lib/parser.js';
|
|
9
9
|
import {parseSchemaMarkdown} from 'schema-markdown/lib/parser.js';
|
|
10
10
|
import {validateType} from 'schema-markdown/lib/schema.js';
|
|
11
11
|
|
|
@@ -178,8 +178,8 @@ const rDatetime = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d{3})?(?:Z|[+-]\d{2
|
|
|
178
178
|
*
|
|
179
179
|
* @param {Object} leftData - The left data array
|
|
180
180
|
* @param {Object} rightData - The left data array
|
|
181
|
-
* @param {string} joinExpr - The join [expression]{@link https://craigahobbs.github.io/
|
|
182
|
-
* @param {?string} [rightExpr = null] - The right join [expression]{@link https://craigahobbs.github.io/
|
|
181
|
+
* @param {string} joinExpr - The join [expression]{@link https://craigahobbs.github.io/bare-script/language/#expressions}
|
|
182
|
+
* @param {?string} [rightExpr = null] - The right join [expression]{@link https://craigahobbs.github.io/bare-script/language/#expressions}
|
|
183
183
|
* @param {boolean} [isLeftJoin = false] - If true, perform a left join (always include left row)
|
|
184
184
|
* @param {?Object} [variables = null] - Additional variables for expression evaluation
|
|
185
185
|
* @param {?Object} [options = null] - The [markdown-script options]{@link module:lib/script~MarkdownScriptOptions}
|
|
@@ -297,7 +297,7 @@ export function addCalculatedField(data, fieldName, expr, variables = null, opti
|
|
|
297
297
|
* Filter data rows
|
|
298
298
|
*
|
|
299
299
|
* @param {Object[]} data - The data array
|
|
300
|
-
* @param {string} expr - The boolean filter [expression]{@link https://craigahobbs.github.io/
|
|
300
|
+
* @param {string} expr - The boolean filter [expression]{@link https://craigahobbs.github.io/bare-script/language/#expressions}
|
|
301
301
|
* @param {?Object} [variables = null] - Additional variables for expression evaluation
|
|
302
302
|
* @param {?Object} [options = null] - The [markdown-script options]{@link module:lib/script~MarkdownScriptOptions}
|
|
303
303
|
* @returns {Object[]} The filtered data array
|
package/lib/script.js
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
// Licensed under the MIT License
|
|
2
2
|
// https://github.com/craigahobbs/markdown-up/blob/main/LICENSE
|
|
3
3
|
|
|
4
|
-
import {executeScriptAsync} from '
|
|
5
|
-
import {lintScript} from '
|
|
4
|
+
import {executeScriptAsync} from 'bare-script/lib/runtimeAsync.js';
|
|
5
|
+
import {lintScript} from 'bare-script/lib/model.js';
|
|
6
6
|
import {markdownElements} from 'markdown-model/lib/elements.js';
|
|
7
7
|
import {parseMarkdown} from 'markdown-model/lib/parser.js';
|
|
8
|
-
import {parseScript} from '
|
|
8
|
+
import {parseScript} from 'bare-script/lib/parser.js';
|
|
9
9
|
|
|
10
10
|
|
|
11
11
|
/**
|
|
12
12
|
* The markdown-script code block function options (based on
|
|
13
|
-
* [
|
|
13
|
+
* [bare-script's options]{@link https://craigahobbs.github.io/bare-script/module-lib_runtime.html#~ExecuteScriptOptions}).
|
|
14
14
|
*
|
|
15
15
|
* @typedef {Object} MarkdownScriptOptions
|
|
16
16
|
* @property {number} fontSize - The font size, in points
|
|
@@ -51,7 +51,7 @@ export async function markdownScriptCodeBlock(codeBlock, options) {
|
|
|
51
51
|
|
|
52
52
|
// Log script execution begin
|
|
53
53
|
let timeBegin;
|
|
54
|
-
if ('logFn' in options) {
|
|
54
|
+
if ('logFn' in options && options.debug) {
|
|
55
55
|
timeBegin = performance.now();
|
|
56
56
|
options.logFn(`MarkdownUp: Executing script at line number ${codeBlock.startLineNumber + 1} ...`);
|
|
57
57
|
}
|
|
@@ -62,8 +62,8 @@ export async function markdownScriptCodeBlock(codeBlock, options) {
|
|
|
62
62
|
// Parse the script
|
|
63
63
|
const script = parseScript(codeBlock.lines, codeBlock.startLineNumber + 1);
|
|
64
64
|
|
|
65
|
-
// Run the
|
|
66
|
-
if ('logFn' in options) {
|
|
65
|
+
// Run the bare-script linter?
|
|
66
|
+
if ('logFn' in options && options.debug) {
|
|
67
67
|
const warnings = lintScript(script);
|
|
68
68
|
const warningPrefix = `MarkdownUp: Script static analysis...`;
|
|
69
69
|
if (warnings.length === 0) {
|
|
@@ -83,7 +83,7 @@ export async function markdownScriptCodeBlock(codeBlock, options) {
|
|
|
83
83
|
}
|
|
84
84
|
|
|
85
85
|
// Log script execution end with timing
|
|
86
|
-
if ('logFn' in options) {
|
|
86
|
+
if ('logFn' in options && options.debug) {
|
|
87
87
|
const timeEnd = performance.now();
|
|
88
88
|
options.logFn(`MarkdownUp: Script executed in ${(timeEnd - timeBegin).toFixed(1)} milliseconds`);
|
|
89
89
|
}
|
package/lib/scriptLibrary.js
CHANGED
|
@@ -63,9 +63,9 @@ export const markdownScriptFunctions = {
|
|
|
63
63
|
// $doc: Join two data arrays
|
|
64
64
|
// $arg leftData: The left data array
|
|
65
65
|
// $arg rightData: The right data array
|
|
66
|
-
// $arg joinExpr: The [join expression](https://craigahobbs.github.io/
|
|
66
|
+
// $arg joinExpr: The [join expression](https://craigahobbs.github.io/bare-script/language/#expressions)
|
|
67
67
|
// $arg rightExpr: Optional (default is null).
|
|
68
|
-
// $arg rightExpr: The right [join expression](https://craigahobbs.github.io/
|
|
68
|
+
// $arg rightExpr: The right [join expression](https://craigahobbs.github.io/bare-script/language/#expressions)
|
|
69
69
|
// $arg isLeftJoin: Optional (default is false). If true, perform a left join (always include left row).
|
|
70
70
|
// $arg variables: Optional (default is null). A variables object for join expression evaluation.
|
|
71
71
|
// $return: The joined data array
|
|
@@ -366,7 +366,7 @@ export const markdownScriptFunctions = {
|
|
|
366
366
|
try {
|
|
367
367
|
await callback([event.clientX - boundingRect.left, event.clientY - boundingRect.top], options);
|
|
368
368
|
} catch ({message}) {
|
|
369
|
-
if ('logFn' in options) {
|
|
369
|
+
if ('logFn' in options && options.debug) {
|
|
370
370
|
options.logFn(`MarkdownUp: Error executing drawOnClick callback: ${message}`);
|
|
371
371
|
}
|
|
372
372
|
}
|
|
@@ -704,7 +704,7 @@ export const markdownScriptFunctions = {
|
|
|
704
704
|
try {
|
|
705
705
|
await callback([], options);
|
|
706
706
|
} catch ({message}) {
|
|
707
|
-
if ('logFn' in options) {
|
|
707
|
+
if ('logFn' in options && options.debug) {
|
|
708
708
|
options.logFn(`MarkdownUp: Error executing windowSetResize callback: ${message}`);
|
|
709
709
|
}
|
|
710
710
|
}
|
|
@@ -725,7 +725,7 @@ export const markdownScriptFunctions = {
|
|
|
725
725
|
try {
|
|
726
726
|
await callback([], options);
|
|
727
727
|
} catch ({message}) {
|
|
728
|
-
if ('logFn' in options) {
|
|
728
|
+
if ('logFn' in options && options.debug) {
|
|
729
729
|
options.logFn(`MarkdownUp: Error executing windowSetTimeout callback: ${message}`);
|
|
730
730
|
}
|
|
731
731
|
}
|
|
@@ -792,7 +792,7 @@ function elementModelWrapCallbacks(elements, options) {
|
|
|
792
792
|
try {
|
|
793
793
|
await elementEventCallback(eventArgs, options);
|
|
794
794
|
} catch ({message}) {
|
|
795
|
-
if ('logFn' in options) {
|
|
795
|
+
if ('logFn' in options && options.debug) {
|
|
796
796
|
options.logFn(`MarkdownUp: Error executing elementModelRender callback: ${message}`);
|
|
797
797
|
}
|
|
798
798
|
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"type": "module",
|
|
3
3
|
"name": "markdown-up",
|
|
4
|
-
"version": "2.0.
|
|
4
|
+
"version": "2.0.2",
|
|
5
5
|
"description": "MarkdownUp is a Markdown viewer",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"markdown",
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
"test": "node --test test/"
|
|
23
23
|
},
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"
|
|
25
|
+
"bare-script": "~2.0",
|
|
26
26
|
"element-model": "~1.1",
|
|
27
27
|
"markdown-model": "~1.8",
|
|
28
28
|
"schema-markdown": "~1.2",
|