markdown-up 1.7.4 → 1.7.5

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
@@ -25,7 +25,7 @@ To host a Markdown resource, download the MarkdownUp application stub to the dir
25
25
  your Markdown files:
26
26
 
27
27
  ~~~
28
- curl -O https://craigahobbs.github.io/markdown-up/static/index.html
28
+ curl -O https://craigahobbs.github.io/markdown-up/extra/index.html
29
29
  ~~~
30
30
 
31
31
  To test your Markdown page, start a local static web server:
@@ -52,7 +52,7 @@ To view a different Markdown resource, set the application's
52
52
  (i.e., "http://127.0.0.1:8000#url=other.md").
53
53
 
54
54
 
55
- ## MarkdownUp Application Options
55
+ ### MarkdownUp Application Options
56
56
 
57
57
  The MarkdownUp application supports the following options:
58
58
 
@@ -60,6 +60,8 @@ The MarkdownUp application supports the following options:
60
60
 
61
61
  - **lineHeight** - The default line height, in em
62
62
 
63
+ - **markdownText** - The default Markdown text
64
+
63
65
  - **menu** - If false, the application menu is hidden
64
66
 
65
67
  - **url** - The default Markdown resource URL
package/lib/app.js CHANGED
@@ -12,6 +12,7 @@ import {barChartCodeBlock} from './barChart.js';
12
12
  import {dataTableCodeBlock} from './dataTable.js';
13
13
  import {evaluateExpression} from 'calc-script/lib/runtime.js';
14
14
  import {lineChartCodeBlock} from './lineChart.js';
15
+ import {markdownScriptFunctions} from './scriptLibrary.js';
15
16
  import {parseExpression} from 'calc-script/lib/parser.js';
16
17
  import {renderElements} from 'element-model/lib/elementModel.js';
17
18
  import {schemaMarkdownDoc} from 'schema-markdown-doc/lib/schemaMarkdownDoc.js';
@@ -21,7 +22,7 @@ import {validateType} from 'schema-markdown/lib/schema.js';
21
22
  // The application's hash parameter type model
22
23
  const markdownUpTypesSmd = `\
23
24
  #
24
- # [MarkdownUp](https://craigahobbs.github.io/markdown-up/) is a Markdown viewer application.
25
+ # [MarkdownUp](https://craigahobbs.github.io/markdown-up/) is a Markdown viewer.
25
26
  #
26
27
  # ## Hash Parameters
27
28
  #
@@ -67,24 +68,25 @@ const markdownUpTypes = new SchemaMarkdownParser(markdownUpTypesSmd).types;
67
68
  * The MarkdownUp application options
68
69
  *
69
70
  * @typedef {Object} MarkdownUpOptions
70
- * @param {number} [fontSize = 12] - The font size, in points
71
- * @param {number} [lineHeight = 1.2] - The line height, in em
72
- * @param {string} [markdownText = null] - The markdown text
73
- * @param {boolean} [menu = true] - If true, show the menu
74
- * @param {string} [url = 'README.md'] - The resource URL
71
+ * @property {number} [fontSize = 12] - The font size, in points
72
+ * @property {number} [lineHeight = 1.2] - The line height, in em
73
+ * @property {?string} [markdownText = null] - The default Markdown text
74
+ * @property {boolean} [menu = true] - If true, show the menu
75
+ * @property {string} [url = 'README.md'] - The default resource URL
75
76
  */
76
77
 
77
78
 
78
79
  /**
79
- * MarkdownUp, a Markdown viewer
80
+ * The MarkdownUp application
80
81
  *
81
82
  * @property {Object} window - The web browser window object
82
83
  * @property {?Object} params - The validated hash parameters object
83
84
  * @property {number} fontSize - The font size, in points
84
85
  * @property {number} lineHeight - The line height, in em
85
- * @property {string} markdownText - The markdown text
86
+ * @property {?string} markdownText - The default Markdown text
86
87
  * @property {boolean} menu - If true, show the menu
87
- * @property {string} url - The resource URL
88
+ * @property {string} url - The default resource URL
89
+ * @property {?function} runtimeWindowResize - The runtime-set window resize event listener function
88
90
  * @property {?number} runtimeTimeoutId - The runtime-set timeout ID
89
91
  */
90
92
  export class MarkdownUp {
@@ -92,7 +94,7 @@ export class MarkdownUp {
92
94
  * Create an application instance
93
95
  *
94
96
  * @param {Object} window - The web browser window object
95
- * @property {Object} [options] - The [application options]{@link module:lib/app~MarkdownUpOptions}
97
+ * @param {Object} [options] - The [application options]{@link module:lib/app~MarkdownUpOptions}
96
98
  */
97
99
  constructor(window, {fontSize = 12, lineHeight = 1.2, markdownText = null, menu = true, url = 'README.md'} = {}) {
98
100
  this.window = window;
@@ -108,8 +110,8 @@ export class MarkdownUp {
108
110
 
109
111
 
110
112
  /**
111
- * Run the application. This method calls render and subscribes to any hash parameter changes to
112
- * re-render on any hash parameter change.
113
+ * Run the application. This method calls the render method and subscribes to hash parameter
114
+ * changes to re-render.
113
115
  */
114
116
  async run() {
115
117
  await this.render();
@@ -121,18 +123,6 @@ export class MarkdownUp {
121
123
  * Render the application
122
124
  */
123
125
  async render() {
124
- // Clear the runtime timeout ID, if one is set
125
- if (this.runtimeTimeoutId !== null) {
126
- this.window.clearTimeout(this.runtimeTimeoutId);
127
- this.runtimeTimeoutId = null;
128
- }
129
-
130
- // Clear the window resize event handler
131
- if (this.runtimeWindowResize !== null) {
132
- this.window.removeEventListener('resize', this.runtimeWindowResize);
133
- this.runtimeWindowResize = null;
134
- }
135
-
136
126
  // Parse the hash parameters and render the application element model
137
127
  let result;
138
128
  let isError = false;
@@ -145,14 +135,28 @@ export class MarkdownUp {
145
135
  if (paramsPrev !== null && JSON.stringify(paramsPrev) === JSON.stringify(this.params)) {
146
136
  return;
147
137
  }
148
-
149
- // Call the application main and validate the result
150
- result = await this.main();
151
138
  } catch ({message}) {
152
- result = {'elements': {'html': 'p', 'elem': {'text': `Error: ${message}`}}};
139
+ result = {
140
+ 'title': 'MarkdownUp',
141
+ 'elements': {'html': 'p', 'elem': {'text': `Error: ${message}`}}
142
+ };
153
143
  isError = true;
154
144
  }
155
145
 
146
+ // Call the application main and validate the result
147
+ this.clearRuntimeCallbacks();
148
+ if (!isError) {
149
+ result = await this.main();
150
+ }
151
+
152
+ // Set the font size
153
+ const fontSize = (this.params !== null && 'fontSize' in this.params ? this.params.fontSize : this.fontSize);
154
+ this.window.document.documentElement.style.setProperty('--markdown-model-font-size', `${fontSize}pt`);
155
+
156
+ // Set the line height
157
+ const lineHeight = (this.params !== null && 'lineHeight' in this.params ? this.params.lineHeight : this.lineHeight);
158
+ this.window.document.documentElement.style.setProperty('--markdown-model-line-height', `${lineHeight}em`);
159
+
156
160
  // Set the window title
157
161
  const title = result.title ?? null;
158
162
  if (title !== null) {
@@ -170,31 +174,16 @@ export class MarkdownUp {
170
174
  this.window.addEventListener('resize', result.resize);
171
175
  }
172
176
 
173
- // Set the font size
174
- const fontSize = this.params !== null && 'fontSize' in this.params ? this.params.fontSize : this.fontSize;
175
- this.window.document.documentElement.style.setProperty('--markdown-model-font-size', `${fontSize}pt`);
176
-
177
- // Set the line height
178
- const lineHeight = this.params !== null && 'lineHeight' in this.params ? this.params.lineHeight : this.lineHeight;
179
- this.window.document.documentElement.style.setProperty('--markdown-model-line-height', `${lineHeight}em`);
180
-
181
177
  // Render the element model
182
178
  renderElements(this.window.document.body, result.elements);
183
179
 
184
180
  // Focus?
185
181
  if ('focus' in result) {
186
- const element = this.window.document.getElementById(result.focus);
187
- if (element !== null) {
188
- element.focus();
189
- if ('selectionStart' in element) {
190
- element.selectionStart = element.value.length;
191
- element.selectionEnd = element.value.length;
192
- }
193
- }
182
+ this.setDocumentFocus(result.focus);
194
183
  }
195
184
 
196
185
  // Navigate?
197
- // Note: This is done after render since it may have no effect (in which case we want to render).
186
+ // Note: This is done after render since it may have no effect (in which case we need to render)
198
187
  if ('location' in result && result.location !== null) {
199
188
  this.window.location.href = result.location;
200
189
  return;
@@ -211,7 +200,7 @@ export class MarkdownUp {
211
200
  /**
212
201
  * Parse and validate the hash parameters
213
202
  *
214
- * @param {?string} paramString - Optional parameter string for testing
203
+ * @param {?string} [paramString = null] - Optional parameter string for testing
215
204
  */
216
205
  updateParams(paramString = null) {
217
206
  // Clear, then validate the hash parameters (may throw)
@@ -225,6 +214,33 @@ export class MarkdownUp {
225
214
  }
226
215
 
227
216
 
217
+ clearRuntimeCallbacks(clearResize = true) {
218
+ // Clear the runtime timeout ID, if one is set
219
+ if (this.runtimeTimeoutId !== null) {
220
+ this.window.clearTimeout(this.runtimeTimeoutId);
221
+ this.runtimeTimeoutId = null;
222
+ }
223
+
224
+ // Clear the window resize event handler
225
+ if (clearResize && this.runtimeWindowResize !== null) {
226
+ this.window.removeEventListener('resize', this.runtimeWindowResize);
227
+ this.runtimeWindowResize = null;
228
+ }
229
+ }
230
+
231
+
232
+ setDocumentFocus(focusId) {
233
+ const element = this.window.document.getElementById(focusId);
234
+ if (element !== null) {
235
+ element.focus();
236
+ if ('selectionStart' in element) {
237
+ element.selectionStart = element.value.length;
238
+ element.selectionEnd = element.value.length;
239
+ }
240
+ }
241
+ }
242
+
243
+
228
244
  /**
229
245
  * The application's main entry point
230
246
  *
@@ -306,32 +322,34 @@ export class MarkdownUp {
306
322
  };
307
323
 
308
324
  // Set any runtime side-effects
309
- if (scriptOptions.runtime.windowLocation !== null) {
310
- result.location = scriptOptions.runtime.windowLocation;
311
- }
312
325
  if (scriptOptions.runtime.documentFocus !== null) {
313
326
  result.focus = scriptOptions.runtime.documentFocus;
314
327
  }
315
328
  if (scriptOptions.runtime.documentTitle !== null) {
316
329
  result.title = scriptOptions.runtime.documentTitle;
317
330
  }
318
- if (scriptOptions.runtime.windowTimeout !== null) {
319
- result.timeout = scriptOptions.runtime.windowTimeout;
331
+ if (scriptOptions.runtime.windowLocation !== null) {
332
+ result.location = scriptOptions.runtime.windowLocation;
320
333
  }
321
334
  if (scriptOptions.runtime.windowResize !== null) {
322
335
  result.resize = scriptOptions.runtime.windowResize;
323
336
  }
337
+ if (scriptOptions.runtime.windowTimeout !== null) {
338
+ result.timeout = scriptOptions.runtime.windowTimeout;
339
+ }
340
+
341
+ // Reset the runtime
342
+ scriptOptions.runtime.reset();
324
343
 
325
344
  return result;
326
345
  }
327
346
 
328
347
 
329
348
  createScriptOptions(resourceURL) {
330
- // Create the script options object
331
349
  const scriptOptions = {
332
350
  // eslint-disable-next-line require-await
333
- 'fetchFn': async (fetchURL, init) => this.window.fetch(fetchURL, init),
334
- 'fontSize': this.params !== null && 'fontSize' in this.params ? this.params.fontSize : this.fontSize,
351
+ 'fetchFn': async (fetchURL, options) => this.window.fetch(fetchURL, options),
352
+ 'fontSize': (this.params !== null && 'fontSize' in this.params ? this.params.fontSize : this.fontSize),
335
353
  'params': this.params,
336
354
  'urlFn': (url) => this.modifyURL(url, resourceURL),
337
355
  'window': this.window
@@ -355,6 +373,7 @@ export class MarkdownUp {
355
373
 
356
374
  // Create the markdown-script runtime
357
375
  const runtime = new MarkdownScriptRuntime(scriptOptions);
376
+ scriptOptions.globals = {...markdownScriptFunctions};
358
377
  scriptOptions.runtime = runtime;
359
378
  scriptOptions.runtimeUpdateFn = () => {
360
379
  // Did script set the document title?
@@ -363,38 +382,22 @@ export class MarkdownUp {
363
382
  }
364
383
 
365
384
  // Did the script set a timeout?
385
+ this.clearRuntimeCallbacks(false);
366
386
  if (runtime.windowTimeout !== null) {
367
- if (this.runtimeTimeoutId !== null) {
368
- this.window.clearTimeout(this.runtimeTimeoutId);
369
- }
370
387
  this.runtimeTimeoutId = this.window.setTimeout(...runtime.windowTimeout);
371
388
  }
372
389
 
373
- // Reset the runtime
374
- const {isDocumentReset} = runtime;
375
- const {windowLocation} = runtime;
376
- const documentElements = runtime.reset();
377
-
378
- // Render the elment model
379
- renderElements(
380
- this.window.document.body,
381
- [
382
- documentElements,
383
- isDocumentReset ? this.burgerElements() : null
384
- ],
385
- isDocumentReset
386
- );
390
+ // Reset the runtime and render
391
+ const {isDocumentReset, windowLocation} = runtime;
392
+ const documentElements = [
393
+ runtime.resetElements(),
394
+ isDocumentReset ? this.burgerElements() : null
395
+ ];
396
+ renderElements(this.window.document.body, documentElements, isDocumentReset);
387
397
 
388
398
  // Focus?
389
399
  if (runtime.documentFocus !== null) {
390
- const element = this.window.document.getElementById(runtime.documentFocus);
391
- if (element !== null) {
392
- element.focus();
393
- if ('selectionStart' in element) {
394
- element.selectionStart = element.value.length;
395
- element.selectionEnd = element.value.length;
396
- }
397
- }
400
+ this.setDocumentFocus(runtime.documentFocus);
398
401
  }
399
402
 
400
403
  // Navigate?
@@ -402,6 +405,9 @@ export class MarkdownUp {
402
405
  if (windowLocation !== null) {
403
406
  this.window.location.href = windowLocation;
404
407
  }
408
+
409
+ // Reset the runtime
410
+ runtime.reset();
405
411
  };
406
412
 
407
413
  return scriptOptions;
package/lib/barChart.js CHANGED
@@ -8,11 +8,14 @@ import {loadChartData} from './data.js';
8
8
  import {validateBarChart} from './model.js';
9
9
 
10
10
 
11
+ /* c8 ignore start */
12
+
13
+
11
14
  /**
12
15
  * Bar chart code block function
13
16
  *
14
17
  * @param {object} codeBlock - The code block model
15
- * @param {Object} [options=null] - The [markdown-script options]{@link module:lib/util~MarkdownScriptOptions}
18
+ * @param {Object} [options=null] - The [markdown-script options]{@link module:lib/script~MarkdownScriptOptions}
16
19
  * @returns {Object} The bar chart element model
17
20
  */
18
21
  export function barChartCodeBlock(codeBlock, options = null) {
@@ -24,7 +27,7 @@ export function barChartCodeBlock(codeBlock, options = null) {
24
27
  * Render a bar chart
25
28
  *
26
29
  * @param {Object} barChart - The bar chart model
27
- * @param {Object} [options=null] - The [markdown-script options]{@link module:lib/util~MarkdownScriptOptions}
30
+ * @param {Object} [options=null] - The [markdown-script options]{@link module:lib/script~MarkdownScriptOptions}
28
31
  * @returns {Object} The bar chart element model
29
32
  */
30
33
  export async function barChartElements(barChart, options = null) {
package/lib/csv.js CHANGED
@@ -4,6 +4,9 @@
4
4
  /** @module lib/csv */
5
5
 
6
6
 
7
+ /* c8 ignore start */
8
+
9
+
7
10
  /**
8
11
  * Parse CSV text to a JSON data array
9
12
  *
@@ -32,6 +35,9 @@ const rCSVFieldSplit = /"?,"?/;
32
35
 
33
36
  /**
34
37
  * Parse a CSV number
38
+ *
39
+ * @param {string} text - The text to parse
40
+ * @returns {number} The parsed number
35
41
  */
36
42
  export function parseCSVNumber(text) {
37
43
  const value = Number.parseFloat(text);
@@ -44,6 +50,9 @@ export function parseCSVNumber(text) {
44
50
 
45
51
  /**
46
52
  * Parse a CSV datetime
53
+ *
54
+ * @param {string} text - The text to parse
55
+ * @returns {Date} The parsed Date
47
56
  */
48
57
  export function parseCSVDatetime(text) {
49
58
  if (rCSVDate.test(text)) {
package/lib/data.js CHANGED
@@ -5,26 +5,30 @@
5
5
 
6
6
  import {parseCSV, parseCSVDatetime, parseCSVNumber} from './csv.js';
7
7
  import {compareValues} from './util.js';
8
- import {encodeMarkdownText} from 'markdown-model/lib/parser.js';
8
+ import {escapeMarkdownText} from 'markdown-model/lib/elements.js';
9
9
  import {evaluateExpression} from 'calc-script/lib/runtime.js';
10
10
  import {parseExpression} from 'calc-script/lib/parser.js';
11
11
 
12
12
 
13
+ /* c8 ignore start */
14
+
15
+
13
16
  // Data expression functions
14
17
  const dataExprFunctions = {
15
- 'markdownEncode': ([text]) => encodeMarkdownText(text)
18
+ 'markdownEscape': ([text]) => escapeMarkdownText(text)
16
19
  };
17
20
 
18
21
 
19
22
  // Helper function to create the data expression's variables argument
20
23
  function createDataVariables(chart, variables = null) {
21
24
  const dataVariables = {...dataExprFunctions};
25
+ const evalOptions = {'globals': dataVariables};
22
26
 
23
27
  // Add the chart model variable expressions
24
28
  if (chart !== null && 'var' in chart) {
25
29
  for (const varName of Object.keys(chart.var)) {
26
30
  const varExpr = parseExpression(chart.var[varName]);
27
- dataVariables[varName] = evaluateExpression(varExpr, dataVariables);
31
+ dataVariables[varName] = evaluateExpression(varExpr, evalOptions);
28
32
  }
29
33
  }
30
34
 
@@ -52,8 +56,8 @@ function createDataVariables(chart, variables = null) {
52
56
  *
53
57
  * @async
54
58
  * @param {Object} chart - The chart model
55
- * @param {Object} [options=null] - The [markdown-script options]{@link module:lib/util~MarkdownScriptOptions}
56
- * @returns {module:lib/data~LoadChartDataResult}
59
+ * @param {Object} [options=null] - The [markdown-script options]{@link module:lib/script~MarkdownScriptOptions}
60
+ * @returns [LoadChartDataResult]{@link module:lib/data~LoadChartDataResult}
57
61
  */
58
62
  export async function loadChartData(chart, options = null) {
59
63
  // Load the data resources
@@ -114,8 +118,8 @@ export async function loadChartData(chart, options = null) {
114
118
  *
115
119
  * @async
116
120
  * @param {Object} dataModel - The data model
117
- * @param {Object} options - The [markdown-script options]{@link module:lib/util~MarkdownScriptOptions}
118
- * @returns {module:lib/data~LoadDataResult}
121
+ * @param {Object} options - The [markdown-script options]{@link module:lib/script~MarkdownScriptOptions}
122
+ * @returns [LoadDataResult]{@link module:lib/data~LoadDataResult}
119
123
  */
120
124
  export async function loadData(dataModel, options) {
121
125
  const dataBases = [dataModel, ...('join' in dataModel ? dataModel.join : [])];
@@ -125,6 +129,7 @@ export async function loadData(dataModel, options) {
125
129
 
126
130
  // Compute the data variable values
127
131
  const dataVariables = options.variables ?? createDataVariables(null);
132
+ const evalOptions = {'globals': dataVariables};
128
133
 
129
134
  // Join the data
130
135
  let [{data}] = dataTypes;
@@ -154,7 +159,7 @@ export async function loadData(dataModel, options) {
154
159
  // Bucket the right rows by the right expression value
155
160
  const rightCategoryRows = {};
156
161
  for (const row of rightData) {
157
- const categoryKey = JSON.stringify(evaluateExpression(rightExpression, dataVariables, row));
162
+ const categoryKey = JSON.stringify(evaluateExpression(rightExpression, evalOptions, row));
158
163
  if (!(categoryKey in rightCategoryRows)) {
159
164
  rightCategoryRows[categoryKey] = [];
160
165
  }
@@ -172,7 +177,7 @@ export async function loadData(dataModel, options) {
172
177
 
173
178
  data = [];
174
179
  for (const row of leftData) {
175
- const categoryKey = JSON.stringify(evaluateExpression(leftExpression, dataVariables, row));
180
+ const categoryKey = JSON.stringify(evaluateExpression(leftExpression, evalOptions, row));
176
181
  if (categoryKey in rightCategoryRows) {
177
182
  for (const rightRow of rightCategoryRows[categoryKey]) {
178
183
  const joinRow = {...row};
@@ -312,11 +317,12 @@ export function addCalculatedField(data, name, expr, variables = null) {
312
317
 
313
318
  // Compute the data variable values
314
319
  const dataVariables = variables ?? createDataVariables(null);
320
+ const evalOptions = {'globals': dataVariables};
315
321
 
316
322
  // Compute the calculated fields for each row
317
323
  let calcType = null;
318
324
  for (const row of data) {
319
- const calcValue = evaluateExpression(calcExpr, dataVariables, row);
325
+ const calcValue = evaluateExpression(calcExpr, evalOptions, row);
320
326
  row[name] = calcValue;
321
327
 
322
328
  // Determine the calculated field type
@@ -359,11 +365,12 @@ export function filterData(data, expr, variables = null) {
359
365
 
360
366
  // Compute the data variable values
361
367
  const dataVariables = variables ?? createDataVariables(null);
368
+ const evalOptions = {'globals': dataVariables};
362
369
 
363
370
  // Filter the data
364
371
  const filteredData = [];
365
372
  for (const row of data) {
366
- if (evaluateExpression(filterExpr, dataVariables, row)) {
373
+ if (evaluateExpression(filterExpr, evalOptions, row)) {
367
374
  filteredData.push(row);
368
375
  }
369
376
  }
@@ -377,7 +384,7 @@ export function filterData(data, expr, variables = null) {
377
384
  * @param {Object} aggregationModel - The aggregation model
378
385
  * @param {Object[]} data - The data array
379
386
  * @param {Object} types - The map of field name to field type ("datetime", "number", "string")
380
- * @returns {module:lib/data~LoadDataResult}
387
+ * @returns [LoadDataResult]{@link module:lib/data~LoadDataResult}
381
388
  */
382
389
  export function aggregateData(aggregationModel, data, types) {
383
390
  // Compute the aggregate field types
package/lib/dataTable.js CHANGED
@@ -10,11 +10,14 @@ import {parseMarkdown} from 'markdown-model/lib/parser.js';
10
10
  import {validateDataTable} from './model.js';
11
11
 
12
12
 
13
+ /* c8 ignore start */
14
+
15
+
13
16
  /**
14
17
  * Data table code block function
15
18
  *
16
19
  * @param {object} codeBlock - The code block model
17
- * @param {Object} [options=null] - The [markdown-script options]{@link module:lib/util~MarkdownScriptOptions}
20
+ * @param {Object} [options=null] - The [markdown-script options]{@link module:lib/script~MarkdownScriptOptions}
18
21
  * @returns {Object} The data table element model
19
22
  */
20
23
  export function dataTableCodeBlock(codeBlock, options = null) {
@@ -26,7 +29,7 @@ export function dataTableCodeBlock(codeBlock, options = null) {
26
29
  * Render a data table
27
30
  *
28
31
  * @param {Object} dataTable - The data table model
29
- * @param {Object} [options=null] - The [markdown-script options]{@link module:lib/util~MarkdownScriptOptions}
32
+ * @param {Object} [options=null] - The [markdown-script options]{@link module:lib/script~MarkdownScriptOptions}
30
33
  * @returns {Object} The data table element model
31
34
  */
32
35
  export async function dataTableElements(dataTable, options = null) {
package/lib/lineChart.js CHANGED
@@ -12,6 +12,9 @@ import {parseExpression} from 'calc-script/lib/parser.js';
12
12
  import {validateLineChart} from './model.js';
13
13
 
14
14
 
15
+ /* c8 ignore start */
16
+
17
+
15
18
  // Line chart defaults
16
19
  const defaultWidth = 640;
17
20
  const defaultHeight = 320;
@@ -42,7 +45,7 @@ const chartLineWidth = 3;
42
45
  * Line chart code block function
43
46
  *
44
47
  * @param {object} codeBlock - The code block model
45
- * @param {Object} [options=null] - The [markdown-script options]{@link module:lib/util~MarkdownScriptOptions}
48
+ * @param {Object} [options=null] - The [markdown-script options]{@link module:lib/script~MarkdownScriptOptions}
46
49
  * @returns {Object} The line chart element model
47
50
  */
48
51
  export function lineChartCodeBlock(codeBlock, options = null) {
@@ -54,7 +57,7 @@ export function lineChartCodeBlock(codeBlock, options = null) {
54
57
  * Render a line chart
55
58
  *
56
59
  * @param {Object} lineChart - The line chart model
57
- * @param {Object} [options=null] - The [markdown-script options]{@link module:lib/util~MarkdownScriptOptions}
60
+ * @param {Object} [options=null] - The [markdown-script options]{@link module:lib/script~MarkdownScriptOptions}
58
61
  * @returns {Object} The line chart element model
59
62
  */
60
63
  export async function lineChartElements(lineChart, options = null) {
@@ -161,8 +164,9 @@ export async function lineChartElements(lineChart, options = null) {
161
164
  }
162
165
 
163
166
  // Calculated expression helper function
167
+ const evalOptions = {'globals': variables};
164
168
  const computeExpr = (exprText, expectedType = null, desc = null) => {
165
- const exprValue = evaluateExpression(parseExpression(exprText), variables);
169
+ const exprValue = evaluateExpression(parseExpression(exprText), evalOptions);
166
170
  if (exprValue !== null && expectedType !== null) {
167
171
  const exprType = getCalculatedValueType(exprValue);
168
172
  if (exprType !== expectedType) {