markdown-up 1.7.0 → 1.7.1
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 +15 -10
- package/lib/script.js +13 -3
- package/package.json +2 -2
package/lib/app.js
CHANGED
|
@@ -8,12 +8,12 @@ import {MarkdownScriptRuntime, markdownScriptCodeBlock} from './script.js';
|
|
|
8
8
|
import {decodeQueryString, encodeQueryString} from 'schema-markdown/lib/encode.js';
|
|
9
9
|
import {getBaseURL, isRelativeURL, markdownElementsAsync} from 'markdown-model/lib/elements.js';
|
|
10
10
|
import {getMarkdownTitle, parseMarkdown} from 'markdown-model/lib/parser.js';
|
|
11
|
-
import {UserTypeElements} from 'schema-markdown-doc/lib/userTypeElements.js';
|
|
12
11
|
import {barChartCodeBlock} from './barChart.js';
|
|
13
12
|
import {dataTableCodeBlock} from './dataTable.js';
|
|
14
13
|
import {evaluateExpression} from 'calc-script/lib/runtime.js';
|
|
15
14
|
import {lineChartCodeBlock} from './lineChart.js';
|
|
16
15
|
import {parseExpression} from 'calc-script/lib/parser.js';
|
|
16
|
+
import {schemaMarkdownDoc} from 'schema-markdown-doc/lib/schemaMarkdownDoc.js';
|
|
17
17
|
|
|
18
18
|
|
|
19
19
|
// The application's hash parameter type model
|
|
@@ -186,7 +186,7 @@ export class MarkdownUp extends ElementApplication {
|
|
|
186
186
|
|
|
187
187
|
// Help
|
|
188
188
|
} else {
|
|
189
|
-
cmdElements =
|
|
189
|
+
cmdElements = schemaMarkdownDoc(this.hashTypes, this.hashType, {'params': encodeQueryString(this.params)});
|
|
190
190
|
}
|
|
191
191
|
}
|
|
192
192
|
|
|
@@ -271,7 +271,7 @@ export class MarkdownUp extends ElementApplication {
|
|
|
271
271
|
|
|
272
272
|
// Render the text as Markdown
|
|
273
273
|
const fontSize = 0.9 * (this.params !== null && 'fontSize' in this.params ? this.params.fontSize : this.fontSize);
|
|
274
|
-
const
|
|
274
|
+
const scriptOptions = {
|
|
275
275
|
fetchFn,
|
|
276
276
|
fontSize,
|
|
277
277
|
'localStorage': this.window.localStorage,
|
|
@@ -282,13 +282,13 @@ export class MarkdownUp extends ElementApplication {
|
|
|
282
282
|
urlFn
|
|
283
283
|
};
|
|
284
284
|
if ('var' in this.params) {
|
|
285
|
-
|
|
285
|
+
scriptOptions.variables = {};
|
|
286
286
|
for (const varName of Object.keys(this.params.var)) {
|
|
287
287
|
const varExpr = parseExpression(this.params.var[varName]);
|
|
288
|
-
|
|
288
|
+
scriptOptions.variables[varName] = evaluateExpression(varExpr, scriptOptions.variables);
|
|
289
289
|
}
|
|
290
290
|
}
|
|
291
|
-
|
|
291
|
+
scriptOptions.runtime = new MarkdownScriptRuntime(scriptOptions);
|
|
292
292
|
const result = {
|
|
293
293
|
'title': markdownTitle,
|
|
294
294
|
'elements': [
|
|
@@ -302,10 +302,10 @@ export class MarkdownUp extends ElementApplication {
|
|
|
302
302
|
// Render the markdown
|
|
303
303
|
cmdElements !== null ? null : await markdownElementsAsync(markdownModel, {
|
|
304
304
|
'codeBlocks': {
|
|
305
|
-
'bar-chart': (language, lines) => barChartCodeBlock(language, lines,
|
|
306
|
-
'data-table': (language, lines) => dataTableCodeBlock(language, lines,
|
|
307
|
-
'line-chart': (language, lines) => lineChartCodeBlock(language, lines,
|
|
308
|
-
'markdown-script': (language, lines) => markdownScriptCodeBlock(language, lines,
|
|
305
|
+
'bar-chart': (language, lines) => barChartCodeBlock(language, lines, scriptOptions),
|
|
306
|
+
'data-table': (language, lines) => dataTableCodeBlock(language, lines, scriptOptions),
|
|
307
|
+
'line-chart': (language, lines) => lineChartCodeBlock(language, lines, scriptOptions),
|
|
308
|
+
'markdown-script': (language, lines) => markdownScriptCodeBlock(language, lines, scriptOptions)
|
|
309
309
|
},
|
|
310
310
|
urlFn,
|
|
311
311
|
'headerIds': true
|
|
@@ -354,6 +354,11 @@ export class MarkdownUp extends ElementApplication {
|
|
|
354
354
|
]
|
|
355
355
|
};
|
|
356
356
|
|
|
357
|
+
// Set document title?
|
|
358
|
+
if (scriptOptions.runtime.documentTitle !== null) {
|
|
359
|
+
result.title = scriptOptions.runtime.documentTitle;
|
|
360
|
+
}
|
|
361
|
+
|
|
357
362
|
return result;
|
|
358
363
|
}
|
|
359
364
|
}
|
package/lib/script.js
CHANGED
|
@@ -6,10 +6,11 @@
|
|
|
6
6
|
import {encodeMarkdownText, getMarkdownTitle, parseMarkdown} from 'markdown-model/lib/parser.js';
|
|
7
7
|
import {validateType, validateTypeModelTypes} from 'schema-markdown/lib/schema.js';
|
|
8
8
|
import {SchemaMarkdownParser} from 'schema-markdown/lib/parser.js';
|
|
9
|
-
import {
|
|
9
|
+
import {encodeQueryString} from 'schema-markdown/lib/encode.js';
|
|
10
10
|
import {executeScriptAsync} from 'calc-script/lib/runtimeAsync.js';
|
|
11
11
|
import {markdownElements} from 'markdown-model/lib/elements.js';
|
|
12
12
|
import {parseScript} from 'calc-script/lib/parser.js';
|
|
13
|
+
import {schemaMarkdownDoc} from 'schema-markdown-doc/lib/schemaMarkdownDoc.js';
|
|
13
14
|
import {typeModel} from 'schema-markdown/lib/typeModel.js';
|
|
14
15
|
|
|
15
16
|
|
|
@@ -96,6 +97,7 @@ const defaultFontSizePx = 12 * pixelsPerPoint;
|
|
|
96
97
|
* @property {Object} globals - The global variables
|
|
97
98
|
* @property {module:lib/util~MarkdownScriptOptions} [options = null] - Markdown script options
|
|
98
99
|
* @property {module:lib/script~ElementPart[]} elementParts - The element model parts to render
|
|
100
|
+
* @property {?string} documentTitle - The document title
|
|
99
101
|
*/
|
|
100
102
|
export class MarkdownScriptRuntime {
|
|
101
103
|
/**
|
|
@@ -175,9 +177,15 @@ export class MarkdownScriptRuntime {
|
|
|
175
177
|
),
|
|
176
178
|
|
|
177
179
|
// Utility functions
|
|
180
|
+
'setDocumentTitle': ([title]) => {
|
|
181
|
+
this.documentTitle = title;
|
|
182
|
+
},
|
|
178
183
|
'setNavigateTimeout': (args) => this.setNavigateTimeout(...args)
|
|
179
184
|
};
|
|
180
185
|
|
|
186
|
+
// The document's title
|
|
187
|
+
this.documentTitle = null;
|
|
188
|
+
|
|
181
189
|
// Element model parts ('drawing', 'markdown')
|
|
182
190
|
this.elementParts = [];
|
|
183
191
|
|
|
@@ -417,8 +425,10 @@ export class MarkdownScriptRuntime {
|
|
|
417
425
|
}
|
|
418
426
|
|
|
419
427
|
schemaPrint(types, typeName) {
|
|
420
|
-
const params = (
|
|
421
|
-
|
|
428
|
+
const params = (
|
|
429
|
+
this.options !== null && 'params' in this.options && this.params !== null ? encodeQueryString(this.options.params) : null
|
|
430
|
+
);
|
|
431
|
+
const elements = schemaMarkdownDoc(types, typeName, {'params': params});
|
|
422
432
|
this.setElements(elements);
|
|
423
433
|
}
|
|
424
434
|
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"type": "module",
|
|
3
3
|
"name": "markdown-up",
|
|
4
|
-
"version": "1.7.
|
|
4
|
+
"version": "1.7.1",
|
|
5
5
|
"description": "JavaScript Markdown viewer application",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"markdown",
|
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
"element-app": "~1.1",
|
|
27
27
|
"markdown-model": "~1.4",
|
|
28
28
|
"schema-markdown": "~1.1",
|
|
29
|
-
"schema-markdown-doc": "~1.
|
|
29
|
+
"schema-markdown-doc": "~1.4"
|
|
30
30
|
},
|
|
31
31
|
"devDependencies": {
|
|
32
32
|
"ava": "~4.2",
|