markdown-up 3.3.5 → 3.3.7
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 +9 -0
- package/lib/scriptLibrary.js +0 -82
- package/package.json +2 -2
package/lib/app.js
CHANGED
|
@@ -108,6 +108,7 @@ export class MarkdownUp {
|
|
|
108
108
|
this.url = (options !== null ? options.url : null) ?? 'README.md';
|
|
109
109
|
this.runtimeWindowResize = null;
|
|
110
110
|
this.runtimeTimeoutId = null;
|
|
111
|
+
this.runtimeCount = 0;
|
|
111
112
|
}
|
|
112
113
|
|
|
113
114
|
|
|
@@ -154,6 +155,7 @@ export class MarkdownUp {
|
|
|
154
155
|
this.window.document.documentElement.style.setProperty('--markdown-model-line-height', `${lineHeight}em`);
|
|
155
156
|
|
|
156
157
|
// Call the application main and validate the result
|
|
158
|
+
this.runtimeCount += 1;
|
|
157
159
|
this.clearRuntimeCallbacks();
|
|
158
160
|
if (!isError) {
|
|
159
161
|
result = await this.main();
|
|
@@ -427,12 +429,19 @@ export class MarkdownUp {
|
|
|
427
429
|
|
|
428
430
|
// Create the markdown-script runtime
|
|
429
431
|
const runtime = new MarkdownScriptRuntime(scriptOptions);
|
|
432
|
+
const {runtimeCount} = this;
|
|
430
433
|
scriptOptions.globals = {...markdownScriptFunctions};
|
|
431
434
|
if (this.globals !== null) {
|
|
432
435
|
Object.assign(scriptOptions.globals, this.globals);
|
|
433
436
|
}
|
|
434
437
|
scriptOptions.runtime = runtime;
|
|
435
438
|
scriptOptions.runtimeUpdateFn = () => {
|
|
439
|
+
// Did a render occur in the middle of this runtime update? If so, just reset the runtime.
|
|
440
|
+
if (this.runtimeCount !== runtimeCount) {
|
|
441
|
+
runtime.reset();
|
|
442
|
+
return;
|
|
443
|
+
}
|
|
444
|
+
|
|
436
445
|
// Did script set the document title?
|
|
437
446
|
if (runtime.documentTitle !== null) {
|
|
438
447
|
this.window.document.title = runtime.documentTitle;
|
package/lib/scriptLibrary.js
CHANGED
|
@@ -75,23 +75,6 @@ const dataTableArgs = valueArgsModel([
|
|
|
75
75
|
//
|
|
76
76
|
|
|
77
77
|
|
|
78
|
-
// $function: documentElementClick
|
|
79
|
-
// $group: Document
|
|
80
|
-
// $doc: Click an element
|
|
81
|
-
// $arg id: The element ID
|
|
82
|
-
function documentElementClick(args, options) {
|
|
83
|
-
const [id] = valueArgsValidate(documentElementClickArgs, args);
|
|
84
|
-
const element = options.window.document.getElementById(id) ?? null;
|
|
85
|
-
if (element !== null) {
|
|
86
|
-
element.click();
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
const documentElementClickArgs = valueArgsModel([
|
|
91
|
-
{'name': 'id', 'type': 'string'}
|
|
92
|
-
]);
|
|
93
|
-
|
|
94
|
-
|
|
95
78
|
// $function: documentFontSize
|
|
96
79
|
// $group: Document
|
|
97
80
|
// $doc: Get the document font size
|
|
@@ -101,68 +84,6 @@ function documentFontSize(unusedArgs, options) {
|
|
|
101
84
|
}
|
|
102
85
|
|
|
103
86
|
|
|
104
|
-
// $function: documentInputFileText
|
|
105
|
-
// $group: Document
|
|
106
|
-
// $doc: Read files as text from a file input element
|
|
107
|
-
// $arg id: The input element ID
|
|
108
|
-
// $return: The array of file text, or null if the element does not exist
|
|
109
|
-
async function documentInputFileText(args, options) {
|
|
110
|
-
const [id] = valueArgsValidate(documentInputFileTextArgs, args);
|
|
111
|
-
const element = options.window.document.getElementById(id) ?? null;
|
|
112
|
-
if (element === null) {
|
|
113
|
-
return null;
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
// Read the files
|
|
117
|
-
const files = [];
|
|
118
|
-
for (const file of element.files) {
|
|
119
|
-
const reader = new options.window.FileReader();
|
|
120
|
-
const text = await new Promise((resolve, reject) => {
|
|
121
|
-
reader.onload = () => resolve(reader.result);
|
|
122
|
-
reader.onerror = () => reject(reader.error);
|
|
123
|
-
reader.readAsText(file);
|
|
124
|
-
});
|
|
125
|
-
files.push(text);
|
|
126
|
-
}
|
|
127
|
-
return files;
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
const documentInputFileTextArgs = valueArgsModel([
|
|
131
|
-
{'name': 'id', 'type': 'string'}
|
|
132
|
-
]);
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
// $function: documentInputFileURL
|
|
136
|
-
// $group: Document
|
|
137
|
-
// $doc: Read files as data URLs from a file input element
|
|
138
|
-
// $arg id: The input element ID
|
|
139
|
-
// $return: The array of file data URL strings, or null if the element does not exist
|
|
140
|
-
async function documentInputFileURL(args, options) {
|
|
141
|
-
const [id] = valueArgsValidate(documentInputFileURLArgs, args);
|
|
142
|
-
const element = options.window.document.getElementById(id) ?? null;
|
|
143
|
-
if (element === null) {
|
|
144
|
-
return null;
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
// Read the files
|
|
148
|
-
const files = [];
|
|
149
|
-
for (const file of element.files) {
|
|
150
|
-
const reader = new options.window.FileReader();
|
|
151
|
-
const dataURL = await new Promise((resolve, reject) => {
|
|
152
|
-
reader.onload = () => resolve(reader.result);
|
|
153
|
-
reader.onerror = () => reject(reader.error);
|
|
154
|
-
reader.readAsDataURL(file);
|
|
155
|
-
});
|
|
156
|
-
files.push(dataURL);
|
|
157
|
-
}
|
|
158
|
-
return files;
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
const documentInputFileURLArgs = valueArgsModel([
|
|
162
|
-
{'name': 'id', 'type': 'string'}
|
|
163
|
-
]);
|
|
164
|
-
|
|
165
|
-
|
|
166
87
|
// $function: documentInputValue
|
|
167
88
|
// $group: Document
|
|
168
89
|
// $doc: Get an input element's value
|
|
@@ -1164,10 +1085,7 @@ function windowWidth(unusedArgs, options) {
|
|
|
1164
1085
|
export const markdownScriptFunctions = {
|
|
1165
1086
|
dataLineChart,
|
|
1166
1087
|
dataTable,
|
|
1167
|
-
documentElementClick,
|
|
1168
1088
|
documentFontSize,
|
|
1169
|
-
documentInputFileText,
|
|
1170
|
-
documentInputFileURL,
|
|
1171
1089
|
documentInputValue,
|
|
1172
1090
|
documentSetFocus,
|
|
1173
1091
|
documentSetReset,
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"type": "module",
|
|
3
3
|
"name": "markdown-up",
|
|
4
|
-
"version": "3.3.
|
|
4
|
+
"version": "3.3.7",
|
|
5
5
|
"description": "MarkdownUp is a Markdown viewer",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"markdown",
|
|
@@ -32,6 +32,6 @@
|
|
|
32
32
|
"c8": "~10.1",
|
|
33
33
|
"eslint": "~9.17",
|
|
34
34
|
"jsdoc": "~4.0",
|
|
35
|
-
"jsdom": "~
|
|
35
|
+
"jsdom": "~26.0"
|
|
36
36
|
}
|
|
37
37
|
}
|