markdown-up 3.1.0 → 3.2.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 +46 -25
- package/lib/dataTable.js +7 -2
- package/lib/script.js +3 -0
- package/lib/scriptLibrary.js +25 -0
- package/package.json +4 -4
package/lib/app.js
CHANGED
|
@@ -41,7 +41,7 @@ struct MarkdownUp
|
|
|
41
41
|
struct MarkdownUpLocal
|
|
42
42
|
|
|
43
43
|
# If set, dark mode is enabled
|
|
44
|
-
optional
|
|
44
|
+
optional bool darkMode
|
|
45
45
|
|
|
46
46
|
# The font size
|
|
47
47
|
optional int(>= 8, <= 18) fontSize
|
|
@@ -75,14 +75,14 @@ enum MarkdownUpView
|
|
|
75
75
|
* The MarkdownUp application options
|
|
76
76
|
*
|
|
77
77
|
* @typedef {Object} MarkdownUpOptions
|
|
78
|
-
* @property {boolean} [darkMode = false] - If true, use dark mode by default
|
|
79
|
-
* @property {number} [fontSize = 12] - The font size, in points
|
|
78
|
+
* @property {?boolean} [darkMode = false] - If true, use dark mode by default
|
|
79
|
+
* @property {?number} [fontSize = 12] - The font size, in points
|
|
80
80
|
* @property {?Object} [globals = null] - Global script runtime variables
|
|
81
|
-
* @property {number} [lineHeight = 1.2] - The line height, in em
|
|
81
|
+
* @property {?number} [lineHeight = 1.2] - The line height, in em
|
|
82
82
|
* @property {?string} [markdownText = null] - The default Markdown text
|
|
83
|
-
* @property {boolean} [menu = true] - If true, show the menu
|
|
84
|
-
* @property {string} [systemPrefix] - The markdown-script system include prefix
|
|
85
|
-
* @property {string} [url = 'README.md'] - The default resource URL
|
|
83
|
+
* @property {?boolean} [menu = true] - If true, show the menu
|
|
84
|
+
* @property {?string} [systemPrefix] - The markdown-script system include prefix
|
|
85
|
+
* @property {?string} [url = 'README.md'] - The default resource URL
|
|
86
86
|
*/
|
|
87
87
|
|
|
88
88
|
|
|
@@ -101,7 +101,8 @@ export class MarkdownUp {
|
|
|
101
101
|
this.params = null;
|
|
102
102
|
this.paramsLocal = null;
|
|
103
103
|
this.paramsSession = null;
|
|
104
|
-
this.darkMode = (options !== null ? options.darkMode : null) ??
|
|
104
|
+
this.darkMode = (options !== null ? options.darkMode : null) ??
|
|
105
|
+
(this.window.matchMedia && this.window.matchMedia('(prefers-color-scheme: dark)').matches);
|
|
105
106
|
this.fontSize = (options !== null ? options.fontSize : null) ?? 12;
|
|
106
107
|
this.globals = (options !== null ? options.globals : null) ?? null;
|
|
107
108
|
this.lineHeight = (options !== null ? options.lineHeight : null) ?? 1.2;
|
|
@@ -339,6 +340,16 @@ export class MarkdownUp {
|
|
|
339
340
|
}
|
|
340
341
|
|
|
341
342
|
// 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
|
+
}
|
|
342
353
|
const result = {
|
|
343
354
|
'title': markdownTitle,
|
|
344
355
|
'elements': [
|
|
@@ -346,13 +357,7 @@ export class MarkdownUp {
|
|
|
346
357
|
this.burgerElements(),
|
|
347
358
|
|
|
348
359
|
// Render the markdown
|
|
349
|
-
await markdownElementsAsync(markdownModel,
|
|
350
|
-
'codeBlocks': {
|
|
351
|
-
'markdown-script': (codeBlock) => markdownScriptCodeBlock(codeBlock, scriptOptions)
|
|
352
|
-
},
|
|
353
|
-
'urlFn': (urlRaw) => this.modifyURL(urlRaw, url),
|
|
354
|
-
'headerIds': true
|
|
355
|
-
})
|
|
360
|
+
await markdownElementsAsync(markdownModel, markdownOptions)
|
|
356
361
|
]
|
|
357
362
|
};
|
|
358
363
|
|
|
@@ -517,9 +522,9 @@ export class MarkdownUp {
|
|
|
517
522
|
'path': 'M4,2 L20,2 L20,22 L4,22 Z',
|
|
518
523
|
'path2': 'M7,7.5 L17,7.5 M7,12 L17,12 M7,16.5 L17,16.5'
|
|
519
524
|
}),
|
|
520
|
-
this.
|
|
525
|
+
this.menuDarkModeToggle({
|
|
521
526
|
'path': 'M16,3 A10,10,0,1,1,3,18 A14,14,0,0,0,17,3'
|
|
522
|
-
}
|
|
527
|
+
}),
|
|
523
528
|
this.menuValueCycle('fontSize', this.fontSize, 2, {
|
|
524
529
|
'path': 'M4,22 L10,2 L14,2 L20,22 M6,14 L18,14',
|
|
525
530
|
'strokeWidth': 4
|
|
@@ -544,18 +549,16 @@ export class MarkdownUp {
|
|
|
544
549
|
}
|
|
545
550
|
|
|
546
551
|
|
|
547
|
-
menuValueToggle(valueName, icon
|
|
548
|
-
|
|
549
|
-
icon.checked = valueName in params;
|
|
552
|
+
menuValueToggle(valueName, icon) {
|
|
553
|
+
icon.checked = valueName in this.paramsSession;
|
|
550
554
|
return this.menuButton(
|
|
551
555
|
() => {
|
|
552
|
-
if (valueName in
|
|
553
|
-
delete
|
|
556
|
+
if (valueName in this.paramsSession) {
|
|
557
|
+
delete this.paramsSession[valueName];
|
|
554
558
|
} else {
|
|
555
|
-
|
|
559
|
+
this.paramsSession[valueName] = 1;
|
|
556
560
|
}
|
|
557
|
-
|
|
558
|
-
storage.setItem('MarkdownUp', JSON.stringify(params));
|
|
561
|
+
this.window.sessionStorage.setItem('MarkdownUp', JSON.stringify(this.paramsSession));
|
|
559
562
|
this.render(true);
|
|
560
563
|
},
|
|
561
564
|
icon
|
|
@@ -580,6 +583,24 @@ export class MarkdownUp {
|
|
|
580
583
|
}
|
|
581
584
|
|
|
582
585
|
|
|
586
|
+
menuDarkModeToggle(icon) {
|
|
587
|
+
const isDarkMode = this.paramsLocal.darkMode ?? this.darkMode;
|
|
588
|
+
icon.checked = isDarkMode;
|
|
589
|
+
return this.menuButton(
|
|
590
|
+
() => {
|
|
591
|
+
if (isDarkMode !== this.darkMode) {
|
|
592
|
+
delete this.paramsLocal.darkMode;
|
|
593
|
+
} else {
|
|
594
|
+
this.paramsLocal.darkMode = !isDarkMode;
|
|
595
|
+
}
|
|
596
|
+
this.window.localStorage.setItem('MarkdownUp', JSON.stringify(this.paramsLocal));
|
|
597
|
+
this.render(true);
|
|
598
|
+
},
|
|
599
|
+
icon
|
|
600
|
+
);
|
|
601
|
+
}
|
|
602
|
+
|
|
603
|
+
|
|
583
604
|
menuValueCycle(valueName, valueDefault, valueDelta, icon) {
|
|
584
605
|
return this.menuButton(
|
|
585
606
|
() => {
|
package/lib/dataTable.js
CHANGED
|
@@ -89,7 +89,9 @@ export function validateDataTable(dataTable) {
|
|
|
89
89
|
* The data table options object
|
|
90
90
|
*
|
|
91
91
|
* @typedef {Object} DataTableOptions
|
|
92
|
-
* @property {function} [
|
|
92
|
+
* @property {?function} [copyFn] - The
|
|
93
|
+
* [Markdown copy function]{@link https://craigahobbs.github.io/markdown-model/module-lib_elements.html#~CopyFn}
|
|
94
|
+
* @property {?function} [urlFn] - The
|
|
93
95
|
* [Markdown URL modifier function]{@link https://craigahobbs.github.io/markdown-model/module-lib_elements.html#~URLFn}
|
|
94
96
|
*/
|
|
95
97
|
|
|
@@ -122,7 +124,10 @@ export function dataTableElements(data, dataTable = null, options = null) {
|
|
|
122
124
|
|
|
123
125
|
// Generate the data table's element model
|
|
124
126
|
const fieldFormats = (dataTable !== null ? (dataTable.formats ?? null) : null);
|
|
125
|
-
const markdownOptions =
|
|
127
|
+
const markdownOptions = {
|
|
128
|
+
'copyFn': (options !== null ? options.copyFn : null) ?? null,
|
|
129
|
+
'urlFn': (options !== null ? options.urlFn : null) ?? null
|
|
130
|
+
};
|
|
126
131
|
const formatPrecision = (dataTable !== null ? (dataTable.precision ?? null) : null);
|
|
127
132
|
const formatDatetime = (dataTable !== null ? (dataTable.datetime ?? null) : null);
|
|
128
133
|
const formatTrim = (dataTable !== null ? (dataTable.trim ?? null) : null);
|
package/lib/script.js
CHANGED
|
@@ -275,6 +275,9 @@ export class MarkdownScriptRuntime {
|
|
|
275
275
|
finishMarkdown() {
|
|
276
276
|
if (this.markdown !== null) {
|
|
277
277
|
const markdownOptions = {'headerIds': true, 'urlFn': this.options.urlFn};
|
|
278
|
+
if (this.options.window.navigator.clipboard) {
|
|
279
|
+
markdownOptions.copyFn = (text) => this.options.window.navigator.clipboard.writeText(text);
|
|
280
|
+
}
|
|
278
281
|
try {
|
|
279
282
|
this.addElements(markdownElements(parseMarkdown(this.markdown), markdownOptions));
|
|
280
283
|
} catch {
|
package/lib/scriptLibrary.js
CHANGED
|
@@ -964,6 +964,29 @@ const urlObjectCreateArgs = valueArgsModel([
|
|
|
964
964
|
//
|
|
965
965
|
|
|
966
966
|
|
|
967
|
+
// $function: windowClipboardRead
|
|
968
|
+
// $group: Window
|
|
969
|
+
// $doc: Read text from the clipboard
|
|
970
|
+
// $return: The clipboard text
|
|
971
|
+
async function windowClipboardRead(args, options) {
|
|
972
|
+
return await options.window.navigator.clipboard.readText();
|
|
973
|
+
}
|
|
974
|
+
|
|
975
|
+
|
|
976
|
+
// $function: windowClipboardWrite
|
|
977
|
+
// $group: Window
|
|
978
|
+
// $doc: Write text to the clipboard
|
|
979
|
+
// $arg text: The text to write
|
|
980
|
+
async function windowClipboardWrite(args, options) {
|
|
981
|
+
const [text] = valueArgsValidate(windowClipboardWriteArgs, args);
|
|
982
|
+
await options.window.navigator.clipboard.writeText(text);
|
|
983
|
+
}
|
|
984
|
+
|
|
985
|
+
const windowClipboardWriteArgs = valueArgsModel([
|
|
986
|
+
{'name': 'text', 'type': 'string'}
|
|
987
|
+
]);
|
|
988
|
+
|
|
989
|
+
|
|
967
990
|
// $function: windowHeight
|
|
968
991
|
// $group: Window
|
|
969
992
|
// $doc: Get the browser window's height
|
|
@@ -1098,6 +1121,8 @@ export const markdownScriptFunctions = {
|
|
|
1098
1121
|
sessionStorageRemove,
|
|
1099
1122
|
sessionStorageSet,
|
|
1100
1123
|
urlObjectCreate,
|
|
1124
|
+
windowClipboardRead,
|
|
1125
|
+
windowClipboardWrite,
|
|
1101
1126
|
windowHeight,
|
|
1102
1127
|
windowSetLocation,
|
|
1103
1128
|
windowSetResize,
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"type": "module",
|
|
3
3
|
"name": "markdown-up",
|
|
4
|
-
"version": "3.1
|
|
4
|
+
"version": "3.2.1",
|
|
5
5
|
"description": "MarkdownUp is a Markdown viewer",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"markdown",
|
|
@@ -24,13 +24,13 @@
|
|
|
24
24
|
"dependencies": {
|
|
25
25
|
"bare-script": "~3.0",
|
|
26
26
|
"element-model": "~1.1",
|
|
27
|
-
"markdown-model": "~2.
|
|
27
|
+
"markdown-model": "~2.1",
|
|
28
28
|
"schema-markdown": "~1.2",
|
|
29
|
-
"schema-markdown-doc": "~1.
|
|
29
|
+
"schema-markdown-doc": "~1.8"
|
|
30
30
|
},
|
|
31
31
|
"devDependencies": {
|
|
32
32
|
"c8": "~10.1",
|
|
33
|
-
"eslint": "~9.
|
|
33
|
+
"eslint": "~9.11",
|
|
34
34
|
"jsdoc": "~4.0",
|
|
35
35
|
"jsdom": "~25.0"
|
|
36
36
|
}
|