markdown-up 3.2.0 → 3.3.0
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 +49 -25
- package/lib/script.js +1 -2
- package/lib/scriptLibrary.js +6 -4
- package/package.json +3 -3
package/lib/app.js
CHANGED
|
@@ -264,40 +264,44 @@ export class MarkdownUp {
|
|
|
264
264
|
|
|
265
265
|
|
|
266
266
|
async main() {
|
|
267
|
+
const url = this.getResourceURL();
|
|
268
|
+
const scriptOptions = this.createScriptOptions();
|
|
269
|
+
|
|
267
270
|
// Help?
|
|
268
271
|
if (this.params.view === 'help') {
|
|
272
|
+
const schemaMarkdownDocOptions = {
|
|
273
|
+
'params': encodeQueryString(this.params),
|
|
274
|
+
'markdownOptions': scriptOptions.markdownOptions
|
|
275
|
+
};
|
|
269
276
|
return {
|
|
270
277
|
'title': 'MarkdownUp',
|
|
271
278
|
'elements': [
|
|
272
279
|
this.burgerElements(),
|
|
273
|
-
schemaMarkdownDoc(markdownUpTypes, 'MarkdownUp',
|
|
280
|
+
schemaMarkdownDoc(markdownUpTypes, 'MarkdownUp', schemaMarkdownDocOptions)
|
|
274
281
|
]
|
|
275
282
|
};
|
|
276
283
|
}
|
|
277
284
|
|
|
278
285
|
// Get the Markdown text
|
|
279
|
-
const urlOverride = 'url' in this.params && this.params.url !== '';
|
|
280
|
-
const url = urlOverride ? this.params.url : this.url;
|
|
281
|
-
const scriptOptions = this.createScriptOptions(url);
|
|
282
286
|
let markdownText;
|
|
283
287
|
let timeBegin;
|
|
284
|
-
if (this.markdownText !== null && !
|
|
288
|
+
if (this.markdownText !== null && !('url' in this.params && this.params.url !== '')) {
|
|
285
289
|
({markdownText} = this);
|
|
286
290
|
|
|
287
291
|
// Log Markdown render begin
|
|
288
|
-
if (
|
|
292
|
+
if (scriptOptions.debug) {
|
|
289
293
|
timeBegin = performance.now();
|
|
290
294
|
scriptOptions.logFn('MarkdownUp: ===== Rendering Markdown text');
|
|
291
295
|
}
|
|
292
296
|
} else {
|
|
293
297
|
// Log Markdown render begin
|
|
294
|
-
if (
|
|
298
|
+
if (scriptOptions.debug) {
|
|
295
299
|
scriptOptions.logFn(`MarkdownUp: ===== Rendering Markdown document "${url}"`);
|
|
296
300
|
}
|
|
297
301
|
|
|
298
302
|
// Log Markdown fetch begin
|
|
299
303
|
let fetchBegin;
|
|
300
|
-
if (
|
|
304
|
+
if (scriptOptions.debug) {
|
|
301
305
|
fetchBegin = performance.now();
|
|
302
306
|
scriptOptions.logFn(`MarkdownUp: Fetching "${url}" ...`);
|
|
303
307
|
}
|
|
@@ -317,7 +321,7 @@ export class MarkdownUp {
|
|
|
317
321
|
markdownText = await response.text();
|
|
318
322
|
|
|
319
323
|
// Log Markdown fetch end with timing
|
|
320
|
-
if (
|
|
324
|
+
if (scriptOptions.debug) {
|
|
321
325
|
const fetchEnd = performance.now();
|
|
322
326
|
timeBegin = performance.now();
|
|
323
327
|
scriptOptions.logFn(`MarkdownUp: Fetch completed in ${(fetchEnd - fetchBegin).toFixed(1)} milliseconds`);
|
|
@@ -339,17 +343,13 @@ export class MarkdownUp {
|
|
|
339
343
|
};
|
|
340
344
|
}
|
|
341
345
|
|
|
346
|
+
// Copy the markdown options and override the markdown-script code block renderer
|
|
347
|
+
const scriptMarkdownOptions = {...scriptOptions.markdownOptions};
|
|
348
|
+
scriptMarkdownOptions.codeBlocks = {...scriptMarkdownOptions.codeBlocks};
|
|
349
|
+
scriptMarkdownOptions.codeBlocks['markdown-script'] =
|
|
350
|
+
(codeBlock, _options) => markdownScriptCodeBlock(codeBlock, scriptOptions);
|
|
351
|
+
|
|
342
352
|
// Render the Markdown
|
|
343
|
-
const markdownOptions = {
|
|
344
|
-
'codeBlocks': {
|
|
345
|
-
'markdown-script': (codeBlock) => markdownScriptCodeBlock(codeBlock, scriptOptions)
|
|
346
|
-
},
|
|
347
|
-
'urlFn': (urlRaw) => this.modifyURL(urlRaw, url),
|
|
348
|
-
'headerIds': true
|
|
349
|
-
};
|
|
350
|
-
if (this.window.navigator.clipboard) {
|
|
351
|
-
markdownOptions.copyFn = (text) => this.window.navigator.clipboard.writeText(text);
|
|
352
|
-
}
|
|
353
353
|
const result = {
|
|
354
354
|
'title': markdownTitle,
|
|
355
355
|
'elements': [
|
|
@@ -357,7 +357,7 @@ export class MarkdownUp {
|
|
|
357
357
|
this.burgerElements(),
|
|
358
358
|
|
|
359
359
|
// Render the markdown
|
|
360
|
-
await markdownElementsAsync(markdownModel,
|
|
360
|
+
await markdownElementsAsync(markdownModel, scriptMarkdownOptions)
|
|
361
361
|
]
|
|
362
362
|
};
|
|
363
363
|
|
|
@@ -382,7 +382,7 @@ export class MarkdownUp {
|
|
|
382
382
|
scriptOptions.runtime.reset();
|
|
383
383
|
|
|
384
384
|
// Log Markdown render end
|
|
385
|
-
if (
|
|
385
|
+
if (scriptOptions.debug) {
|
|
386
386
|
const timeEnd = performance.now();
|
|
387
387
|
scriptOptions.logFn(`MarkdownUp: Markdown rendered in ${(timeEnd - timeBegin).toFixed(1)} milliseconds`);
|
|
388
388
|
}
|
|
@@ -391,7 +391,28 @@ export class MarkdownUp {
|
|
|
391
391
|
}
|
|
392
392
|
|
|
393
393
|
|
|
394
|
-
|
|
394
|
+
getResourceURL() {
|
|
395
|
+
if ('url' in this.params && this.params.url !== '') {
|
|
396
|
+
return this.params.url;
|
|
397
|
+
}
|
|
398
|
+
return this.url;
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
|
|
402
|
+
createScriptOptions() {
|
|
403
|
+
// Create the markdown options object
|
|
404
|
+
const urlFn = (url) => this.modifyURL(url);
|
|
405
|
+
const markdownOptions = {
|
|
406
|
+
'codeBlocks': {},
|
|
407
|
+
urlFn,
|
|
408
|
+
'headerIds': true,
|
|
409
|
+
'usedHeaderIds': new Set()
|
|
410
|
+
};
|
|
411
|
+
if (this.window.navigator.clipboard) {
|
|
412
|
+
markdownOptions.copyFn = (text) => this.window.navigator.clipboard.writeText(text);
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
// Create the script options object
|
|
395
416
|
const logFn = (text) => {
|
|
396
417
|
this.window.console.log(text);
|
|
397
418
|
};
|
|
@@ -401,9 +422,10 @@ export class MarkdownUp {
|
|
|
401
422
|
'fetchFn': async (fetchURL, options) => this.window.fetch(fetchURL, options),
|
|
402
423
|
'fontSize': this.paramsLocal.fontSize ?? this.fontSize,
|
|
403
424
|
logFn,
|
|
425
|
+
markdownOptions,
|
|
404
426
|
'params': this.params,
|
|
405
427
|
'systemPrefix': this.systemPrefix,
|
|
406
|
-
|
|
428
|
+
urlFn,
|
|
407
429
|
'window': this.window
|
|
408
430
|
};
|
|
409
431
|
|
|
@@ -415,7 +437,7 @@ export class MarkdownUp {
|
|
|
415
437
|
try {
|
|
416
438
|
scriptOptions.variables[varName] = evaluateExpression(parseExpression(varExprStr), scriptOptions.variables);
|
|
417
439
|
} catch ({message}) {
|
|
418
|
-
if (
|
|
440
|
+
if (scriptOptions.debug) {
|
|
419
441
|
logFn(`MarkdownUp: Error evaluating variable "${varName}" expression "${varExprStr}": ${message}`);
|
|
420
442
|
}
|
|
421
443
|
}
|
|
@@ -474,7 +496,9 @@ export class MarkdownUp {
|
|
|
474
496
|
}
|
|
475
497
|
|
|
476
498
|
|
|
477
|
-
modifyURL(url
|
|
499
|
+
modifyURL(url) {
|
|
500
|
+
const resourceURL = this.getResourceURL();
|
|
501
|
+
|
|
478
502
|
// Hash URL?
|
|
479
503
|
if (url.startsWith('#')) {
|
|
480
504
|
// Fixup the "url" param if its relative
|
package/lib/script.js
CHANGED
|
@@ -274,9 +274,8 @@ export class MarkdownScriptRuntime {
|
|
|
274
274
|
// Helper method to finish the current Markdown block and add its elements
|
|
275
275
|
finishMarkdown() {
|
|
276
276
|
if (this.markdown !== null) {
|
|
277
|
-
const markdownOptions = {'headerIds': true, 'copyFn': this.options.copyFn, 'urlFn': this.options.urlFn};
|
|
278
277
|
try {
|
|
279
|
-
this.addElements(markdownElements(parseMarkdown(this.markdown), markdownOptions));
|
|
278
|
+
this.addElements(markdownElements(parseMarkdown(this.markdown), this.options.markdownOptions));
|
|
280
279
|
} catch {
|
|
281
280
|
// Do nothing
|
|
282
281
|
}
|
package/lib/scriptLibrary.js
CHANGED
|
@@ -864,8 +864,10 @@ const markdownTitleArgs = valueArgsModel([
|
|
|
864
864
|
// $return: The schema type's documentation [element model](https://github.com/craigahobbs/element-model#readme)
|
|
865
865
|
function schemaElements(args, options) {
|
|
866
866
|
const [types, typeName, actionURLs = null] = valueArgsValidate(schemaElementsArgs, args);
|
|
867
|
-
const
|
|
868
|
-
|
|
867
|
+
const schemaOptions = {
|
|
868
|
+
'params': encodeQueryString(options.params),
|
|
869
|
+
'markdownOptions': options.markdownOptions
|
|
870
|
+
};
|
|
869
871
|
if (actionURLs !== null) {
|
|
870
872
|
schemaOptions.actionURLs = actionURLs;
|
|
871
873
|
}
|
|
@@ -1023,7 +1025,7 @@ function windowSetResize(args, options) {
|
|
|
1023
1025
|
try {
|
|
1024
1026
|
await callback([], options);
|
|
1025
1027
|
} catch ({message}) {
|
|
1026
|
-
if (
|
|
1028
|
+
if (options.debug) {
|
|
1027
1029
|
options.logFn(`MarkdownUp: Error executing windowSetResize callback: ${message}`);
|
|
1028
1030
|
}
|
|
1029
1031
|
}
|
|
@@ -1050,7 +1052,7 @@ function windowSetTimeout(args, options) {
|
|
|
1050
1052
|
try {
|
|
1051
1053
|
await callback([], options);
|
|
1052
1054
|
} catch ({message}) {
|
|
1053
|
-
if (
|
|
1055
|
+
if (options.debug) {
|
|
1054
1056
|
options.logFn(`MarkdownUp: Error executing windowSetTimeout callback: ${message}`);
|
|
1055
1057
|
}
|
|
1056
1058
|
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"type": "module",
|
|
3
3
|
"name": "markdown-up",
|
|
4
|
-
"version": "3.
|
|
4
|
+
"version": "3.3.0",
|
|
5
5
|
"description": "MarkdownUp is a Markdown viewer",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"markdown",
|
|
@@ -24,9 +24,9 @@
|
|
|
24
24
|
"dependencies": {
|
|
25
25
|
"bare-script": "~3.0",
|
|
26
26
|
"element-model": "~1.1",
|
|
27
|
-
"markdown-model": "~2.
|
|
27
|
+
"markdown-model": "~2.2",
|
|
28
28
|
"schema-markdown": "~1.2",
|
|
29
|
-
"schema-markdown-doc": "~
|
|
29
|
+
"schema-markdown-doc": "~2.0"
|
|
30
30
|
},
|
|
31
31
|
"devDependencies": {
|
|
32
32
|
"c8": "~10.1",
|