markdown-up 5.1.0 → 5.2.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 +3 -3
- package/lib/scriptLibrary.js +22 -9
- package/package.json +5 -5
package/lib/app.js
CHANGED
|
@@ -6,9 +6,9 @@
|
|
|
6
6
|
import {MarkdownScriptRuntime, markdownScriptCodeBlock} from './script.js';
|
|
7
7
|
import {barescriptParseExpression, evaluateExpression} from 'bare-script/lib/runtime.js';
|
|
8
8
|
import {elementModelWrapCallbacks, markdownScriptFunctions} from './scriptLibrary.js';
|
|
9
|
-
import {
|
|
10
|
-
|
|
11
|
-
|
|
9
|
+
import {
|
|
10
|
+
markdownElementsAsync, markdownParse, markdownTitle, schemaParse, schemaValidate, urlDecodeQueryString, urlEncodeQueryString
|
|
11
|
+
} from 'bare-script/lib/include.js';
|
|
12
12
|
import {renderElements} from 'element-model/lib/elementModel.js';
|
|
13
13
|
import {valueJSON} from 'bare-script/lib/value.js';
|
|
14
14
|
|
package/lib/scriptLibrary.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// Licensed under the MIT License
|
|
2
2
|
// https://github.com/craigahobbs/markdown-up/blob/main/LICENSE
|
|
3
3
|
|
|
4
|
-
import {valueArgsModel, valueArgsValidate} from 'bare-script/lib/value.js';
|
|
4
|
+
import {ValueArgsError, valueArgsModel, valueArgsValidate} from 'bare-script/lib/value.js';
|
|
5
5
|
import {validateElements} from 'element-model/lib/elementModel.js';
|
|
6
6
|
|
|
7
7
|
|
|
@@ -402,21 +402,30 @@ async function windowClipboardRead(args, options) {
|
|
|
402
402
|
|
|
403
403
|
// $function: windowClipboardWrite
|
|
404
404
|
// $group: window
|
|
405
|
-
// $doc: Write text to the clipboard
|
|
406
|
-
// $arg text: The text to write
|
|
407
|
-
// $arg type: The clipboard content type (default is "text/plain")
|
|
405
|
+
// $doc: Write text (or binary data) to the clipboard
|
|
406
|
+
// $arg text: The text string or byte value array (integers 0 to 255) to write
|
|
407
|
+
// $arg type: The clipboard content type (default is "text/plain"). Binary data needs its content type, e.g. "image/png".
|
|
408
408
|
async function windowClipboardWrite(args, options) {
|
|
409
409
|
const [text, type] = valueArgsValidate(windowClipboardWriteArgs, args);
|
|
410
|
-
|
|
410
|
+
if (typeof text !== 'string' && !(Array.isArray(text) && text.every(windowIsByte))) {
|
|
411
|
+
throw new ValueArgsError('text', text);
|
|
412
|
+
}
|
|
413
|
+
const blob = new Blob([typeof text === 'string' ? text : new Uint8Array(text)], {type});
|
|
411
414
|
await options.window.navigator.clipboard.write([new options.window.ClipboardItem({[type]: blob})]);
|
|
412
415
|
}
|
|
413
416
|
|
|
414
417
|
const windowClipboardWriteArgs = valueArgsModel([
|
|
415
|
-
{'name': 'text'
|
|
418
|
+
{'name': 'text'},
|
|
416
419
|
{'name': 'type', 'type': 'string', 'default': 'text/plain'}
|
|
417
420
|
]);
|
|
418
421
|
|
|
419
422
|
|
|
423
|
+
// Helper to test if a value is a byte value (an integer 0 to 255)
|
|
424
|
+
function windowIsByte(value) {
|
|
425
|
+
return typeof value === 'number' && Number.isInteger(value) && value >= 0 && value <= 255;
|
|
426
|
+
}
|
|
427
|
+
|
|
428
|
+
|
|
420
429
|
// $function: windowHeight
|
|
421
430
|
// $group: window
|
|
422
431
|
// $doc: Get the browser window's height
|
|
@@ -767,16 +776,20 @@ const windowSetTimeoutArgs = valueArgsModel([
|
|
|
767
776
|
// $function: windowURLObject
|
|
768
777
|
// $group: window
|
|
769
778
|
// $doc: Create an object URL (i.e. a file download URL)
|
|
770
|
-
// $arg data: The object data string
|
|
779
|
+
// $arg data: The object data string or byte value array (integers 0 to 255)
|
|
771
780
|
// $arg contentType: Optional (default is "text/plain"). The object content type.
|
|
772
781
|
// $return: The object URL string
|
|
773
782
|
function windowURLObject(args, options) {
|
|
774
783
|
const [data, contentType] = valueArgsValidate(windowURLObjectArgs, args);
|
|
775
|
-
|
|
784
|
+
if (typeof data !== 'string' && !(Array.isArray(data) && data.every(windowIsByte))) {
|
|
785
|
+
throw new ValueArgsError('data', data);
|
|
786
|
+
}
|
|
787
|
+
const blobData = (typeof data === 'string' ? data : new Uint8Array(data));
|
|
788
|
+
return options.window.URL.createObjectURL(new Blob([blobData], {'type': contentType}));
|
|
776
789
|
}
|
|
777
790
|
|
|
778
791
|
const windowURLObjectArgs = valueArgsModel([
|
|
779
|
-
{'name': 'data'
|
|
792
|
+
{'name': 'data'},
|
|
780
793
|
{'name': 'contentType', 'type': 'string', 'default': 'text/plain'}
|
|
781
794
|
]);
|
|
782
795
|
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"type": "module",
|
|
3
3
|
"name": "markdown-up",
|
|
4
|
-
"version": "5.
|
|
4
|
+
"version": "5.2.0",
|
|
5
5
|
"description": "MarkdownUp is a Markdown viewer",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"markdown",
|
|
@@ -22,15 +22,15 @@
|
|
|
22
22
|
"test": "node --test test/"
|
|
23
23
|
},
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"bare-script": "~5.
|
|
25
|
+
"bare-script": "~5.2",
|
|
26
26
|
"element-model": "~1.2"
|
|
27
27
|
},
|
|
28
28
|
"devDependencies": {
|
|
29
29
|
"@eslint/js": "~10.0",
|
|
30
30
|
"c8": "~12.0",
|
|
31
|
-
"eslint": "~10.
|
|
32
|
-
"globals": "~17.
|
|
31
|
+
"eslint": "~10.12",
|
|
32
|
+
"globals": "~17.13",
|
|
33
33
|
"jsdoc": "~4.0",
|
|
34
|
-
"jsdom": "~30.
|
|
34
|
+
"jsdom": "~30.1"
|
|
35
35
|
}
|
|
36
36
|
}
|