markdown-up 3.3.2 → 3.3.4
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/README.md +1 -3
- package/lib/app.js +14 -27
- package/lib/script.js +1 -1
- package/lib/scriptLibrary.js +82 -0
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -52,9 +52,7 @@ application stub file, index.html. For example:
|
|
|
52
52
|
...
|
|
53
53
|
~~~
|
|
54
54
|
|
|
55
|
-
To view a different Markdown resource, set the application's
|
|
56
|
-
["url" hash parameter](https://craigahobbs.github.io/markdown-up/#cmd.help=1)
|
|
57
|
-
(i.e., "http://127.0.0.1:8000#url=other.md").
|
|
55
|
+
To view a different Markdown resource, set the application's "url" hash parameter (i.e., "http://127.0.0.1:8000#url=other.md").
|
|
58
56
|
|
|
59
57
|
|
|
60
58
|
## Dynamic Markdown Applications
|
package/lib/app.js
CHANGED
|
@@ -12,19 +12,12 @@ import {markdownScriptFunctions} from './scriptLibrary.js';
|
|
|
12
12
|
import {parseExpression} from 'bare-script/lib/parser.js';
|
|
13
13
|
import {parseSchemaMarkdown} from 'schema-markdown/lib/parser.js';
|
|
14
14
|
import {renderElements} from 'element-model/lib/elementModel.js';
|
|
15
|
-
import {schemaMarkdownDoc} from 'schema-markdown-doc/lib/schemaMarkdownDoc.js';
|
|
16
15
|
import {validateType} from 'schema-markdown/lib/schema.js';
|
|
17
16
|
|
|
18
17
|
|
|
19
18
|
// The application's hash parameter type model
|
|
20
19
|
const markdownUpTypes = parseSchemaMarkdown(`\
|
|
21
|
-
#
|
|
22
|
-
# [MarkdownUp](https://github.com/craigahobbs/markdown-up#readme) is a Markdown viewer.
|
|
23
|
-
#
|
|
24
|
-
# ## Hash Parameters
|
|
25
|
-
#
|
|
26
|
-
# MarkdownUp recognizes the following hash parameters:
|
|
27
|
-
#
|
|
20
|
+
# The MarkdownUp hash parameters
|
|
28
21
|
struct MarkdownUp
|
|
29
22
|
|
|
30
23
|
# The resource URL
|
|
@@ -63,9 +56,6 @@ struct MarkdownUpSession
|
|
|
63
56
|
# A MarkdownUp application view
|
|
64
57
|
enum MarkdownUpView
|
|
65
58
|
|
|
66
|
-
# Display the hash parameters documentation
|
|
67
|
-
help
|
|
68
|
-
|
|
69
59
|
# Show the resource's Markdown text
|
|
70
60
|
markdown
|
|
71
61
|
`);
|
|
@@ -81,6 +71,7 @@ enum MarkdownUpView
|
|
|
81
71
|
* @property {?boolean} [darkMode = false] - If true, use dark mode by default
|
|
82
72
|
* @property {?number} [fontSize = 12] - The font size, in points
|
|
83
73
|
* @property {?Object} [globals = null] - Global script runtime variables
|
|
74
|
+
* @property {?string} [helpURL] - The help URL
|
|
84
75
|
* @property {?number} [lineHeight = 1.2] - The line height, in em
|
|
85
76
|
* @property {?string} [markdownText = null] - The default Markdown text
|
|
86
77
|
* @property {?boolean} [menu = true] - If true, show the menu
|
|
@@ -109,6 +100,7 @@ export class MarkdownUp {
|
|
|
109
100
|
(this.window.matchMedia && this.window.matchMedia('(prefers-color-scheme: dark)').matches);
|
|
110
101
|
this.fontSize = (options !== null ? options.fontSize : null) ?? 12;
|
|
111
102
|
this.globals = (options !== null ? options.globals : null) ?? null;
|
|
103
|
+
this.helpURL = (options !== null ? options.helpURL : null) ?? 'https://craigahobbs.github.io/markdown-up';
|
|
112
104
|
this.lineHeight = (options !== null ? options.lineHeight : null) ?? 1.2;
|
|
113
105
|
this.markdownText = (options !== null ? options.markdownText : null) ?? null;
|
|
114
106
|
this.menu = (options !== null ? options.menu : null) ?? true;
|
|
@@ -271,21 +263,6 @@ export class MarkdownUp {
|
|
|
271
263
|
const url = this.getResourceURL();
|
|
272
264
|
const scriptOptions = this.createScriptOptions();
|
|
273
265
|
|
|
274
|
-
// Help?
|
|
275
|
-
if (this.params.view === 'help') {
|
|
276
|
-
const schemaMarkdownDocOptions = {
|
|
277
|
-
'params': encodeQueryString(this.params),
|
|
278
|
-
'markdownOptions': scriptOptions.markdownOptions
|
|
279
|
-
};
|
|
280
|
-
return {
|
|
281
|
-
'title': 'MarkdownUp',
|
|
282
|
-
'elements': [
|
|
283
|
-
this.burgerElements(),
|
|
284
|
-
schemaMarkdownDoc(markdownUpTypes, 'MarkdownUp', schemaMarkdownDocOptions)
|
|
285
|
-
]
|
|
286
|
-
};
|
|
287
|
-
}
|
|
288
|
-
|
|
289
266
|
// Get the Markdown text
|
|
290
267
|
let markdownText;
|
|
291
268
|
let timeBegin;
|
|
@@ -564,7 +541,7 @@ export class MarkdownUp {
|
|
|
564
541
|
'path': 'M12,5 A4,7,0,1,0,12,19 A4,7,0,1,0,12,5 M9,9 L15,9 M9,9 L4,6 M9,12 L3,12 M9,15 L4,18 ' +
|
|
565
542
|
'M15,9 L20,6 M15,12 L21,12 M15,15 L20,18'
|
|
566
543
|
}),
|
|
567
|
-
this.
|
|
544
|
+
this.menuLink(this.helpURL, {
|
|
568
545
|
'path': 'M7,9 L7,4 L17,4 L17,12 L12,12 L12,16 M12,19 L12,22'
|
|
569
546
|
})
|
|
570
547
|
]
|
|
@@ -577,6 +554,16 @@ export class MarkdownUp {
|
|
|
577
554
|
}
|
|
578
555
|
|
|
579
556
|
|
|
557
|
+
menuLink(url, icon) {
|
|
558
|
+
return this.menuButton(
|
|
559
|
+
() => {
|
|
560
|
+
this.window.location.href = url;
|
|
561
|
+
},
|
|
562
|
+
icon
|
|
563
|
+
);
|
|
564
|
+
}
|
|
565
|
+
|
|
566
|
+
|
|
580
567
|
menuValueToggle(valueName, icon) {
|
|
581
568
|
icon.checked = valueName in this.paramsSession;
|
|
582
569
|
return this.menuButton(
|
package/lib/script.js
CHANGED
|
@@ -14,7 +14,7 @@ import {parseScript} from 'bare-script/lib/parser.js';
|
|
|
14
14
|
*
|
|
15
15
|
* @typedef {Object} MarkdownScriptOptions
|
|
16
16
|
* @property {number} fontSize - The font size, in points
|
|
17
|
-
* @property {Object} params - The
|
|
17
|
+
* @property {Object} params - The hash parameters object
|
|
18
18
|
* @property {Object} runtime - The [markdown-script runtime state]{@link module:lib/script.MarkdownScriptRuntime}
|
|
19
19
|
* @property {Object} [variables] - The map of variable name to variable value
|
|
20
20
|
* @property {Object} window - The web browser window object
|
package/lib/scriptLibrary.js
CHANGED
|
@@ -75,6 +75,23 @@ 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
|
+
|
|
78
95
|
// $function: documentFontSize
|
|
79
96
|
// $group: Document
|
|
80
97
|
// $doc: Get the document font size
|
|
@@ -84,6 +101,68 @@ function documentFontSize(unusedArgs, options) {
|
|
|
84
101
|
}
|
|
85
102
|
|
|
86
103
|
|
|
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
|
+
|
|
87
166
|
// $function: documentInputValue
|
|
88
167
|
// $group: Document
|
|
89
168
|
// $doc: Get an input element's value
|
|
@@ -1085,7 +1164,10 @@ function windowWidth(unusedArgs, options) {
|
|
|
1085
1164
|
export const markdownScriptFunctions = {
|
|
1086
1165
|
dataLineChart,
|
|
1087
1166
|
dataTable,
|
|
1167
|
+
documentElementClick,
|
|
1088
1168
|
documentFontSize,
|
|
1169
|
+
documentInputFileText,
|
|
1170
|
+
documentInputFileURL,
|
|
1089
1171
|
documentInputValue,
|
|
1090
1172
|
documentSetFocus,
|
|
1091
1173
|
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.4",
|
|
5
5
|
"description": "MarkdownUp is a Markdown viewer",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"markdown",
|
|
@@ -30,7 +30,7 @@
|
|
|
30
30
|
},
|
|
31
31
|
"devDependencies": {
|
|
32
32
|
"c8": "~10.1",
|
|
33
|
-
"eslint": "~9.
|
|
33
|
+
"eslint": "~9.17",
|
|
34
34
|
"jsdoc": "~4.0",
|
|
35
35
|
"jsdom": "~25.0"
|
|
36
36
|
}
|