markdown-up 1.3.0 → 1.5.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/README.md +6 -4
- package/lib/app.js +84 -23
- package/package.json +8 -7
package/README.md
CHANGED
|
@@ -25,8 +25,9 @@ Alternatively, you can change the default Markdown file by updating the markdown
|
|
|
25
25
|
|
|
26
26
|
```
|
|
27
27
|
<script type="module">
|
|
28
|
-
import {MarkdownUp} from 'https://craigahobbs.github.io/markdown-up/
|
|
29
|
-
MarkdownUp
|
|
28
|
+
import {MarkdownUp} from 'https://craigahobbs.github.io/markdown-up/lib/app.js';
|
|
29
|
+
const app = new MarkdownUp(window, {'url': 'other.md'});
|
|
30
|
+
app.run();
|
|
30
31
|
</script>
|
|
31
32
|
```
|
|
32
33
|
|
|
@@ -49,8 +50,9 @@ To view local Markdown files using markdown-up, try the
|
|
|
49
50
|
|
|
50
51
|
## Development
|
|
51
52
|
|
|
52
|
-
|
|
53
|
-
using [javascript-
|
|
53
|
+
markdown-up is an [Element Application](https://github.com/craigahobbs/element-app#readme).
|
|
54
|
+
It is developed using [javascript-build](https://github.com/craigahobbs/javascript-build#readme)
|
|
55
|
+
and it was started using [javascript-template](https://github.com/craigahobbs/javascript-template#readme):
|
|
54
56
|
|
|
55
57
|
```
|
|
56
58
|
template-specialize javascript-template/template/ markdown-up/ -k package markdown-up -k name 'Craig A. Hobbs' -k email 'craigahobbs@gmail.com' -k github 'craigahobbs'
|
package/lib/app.js
CHANGED
|
@@ -1,9 +1,19 @@
|
|
|
1
1
|
// Licensed under the MIT License
|
|
2
2
|
// https://github.com/craigahobbs/markdown-up/blob/main/LICENSE
|
|
3
3
|
|
|
4
|
+
/** @module lib/app */
|
|
5
|
+
|
|
4
6
|
import {ElementApplication, encodeHashID, getHashID} from 'element-app/lib/app.js';
|
|
5
|
-
import {decodeQueryString, encodeQueryString} from 'schema-markdown/
|
|
6
|
-
import {getBaseURL,
|
|
7
|
+
import {decodeQueryString, encodeQueryString} from 'schema-markdown/lib/encode.js';
|
|
8
|
+
import {getBaseURL, isRelativeURL, markdownElements} from 'markdown-model/lib/elements.js';
|
|
9
|
+
import {UserTypeElements} from 'schema-markdown-doc/lib/userTypeElements.js';
|
|
10
|
+
import {barChartCodeBlock} from 'markdown-charts/lib/barChart.js';
|
|
11
|
+
import {chartModel} from 'markdown-charts/lib/model.js';
|
|
12
|
+
import {dataTableCodeBlock} from 'markdown-charts/lib/dataTable.js';
|
|
13
|
+
import {drawingCodeBlock} from 'markdown-charts/lib/drawing.js';
|
|
14
|
+
import {getMarkdownTitle} from 'markdown-model/lib/markdownModel.js';
|
|
15
|
+
import {lineChartCodeBlock} from 'markdown-charts/lib/lineChart.js';
|
|
16
|
+
import {parseMarkdown} from 'markdown-model/lib/parser.js';
|
|
7
17
|
|
|
8
18
|
|
|
9
19
|
// The application's hash parameter type model
|
|
@@ -34,22 +44,47 @@ struct MarkdownUp
|
|
|
34
44
|
# The line height
|
|
35
45
|
optional int(>= 1, <= 2) lineHeight
|
|
36
46
|
|
|
47
|
+
# Variable collection
|
|
48
|
+
optional FieldValue{len > 0} variables
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
# Field value union
|
|
52
|
+
union FieldValue
|
|
53
|
+
|
|
54
|
+
# A datetime value
|
|
55
|
+
datetime(nullable) datetime
|
|
56
|
+
|
|
57
|
+
# A number value
|
|
58
|
+
float(nullable) number
|
|
59
|
+
|
|
60
|
+
# A string value
|
|
61
|
+
string(nullable) string
|
|
62
|
+
|
|
63
|
+
|
|
37
64
|
# Application command union
|
|
38
65
|
union Command
|
|
39
66
|
|
|
40
|
-
#
|
|
41
|
-
|
|
67
|
+
# Display the application's hash parameter documentation
|
|
68
|
+
HelpType help
|
|
42
69
|
|
|
43
70
|
# Show the URL's Markdown text
|
|
44
71
|
int(== 1) markdown
|
|
72
|
+
|
|
73
|
+
# Help type enum
|
|
74
|
+
enum HelpType
|
|
75
|
+
Help
|
|
76
|
+
Bar
|
|
77
|
+
Line
|
|
78
|
+
Table
|
|
45
79
|
`;
|
|
46
80
|
|
|
47
81
|
|
|
48
82
|
/**
|
|
49
|
-
* MarkdownUp, a web application for viewing Markdown files
|
|
83
|
+
* MarkdownUp, a web application for viewing Markdown files
|
|
50
84
|
*
|
|
51
|
-
*
|
|
52
|
-
* [
|
|
85
|
+
* The MarkdownUp class extends the element-app
|
|
86
|
+
* [ElementApplication]{@link https://craigahobbs.github.io/element-app/module-lib_app.ElementApplication.html}
|
|
87
|
+
* class.
|
|
53
88
|
*
|
|
54
89
|
* @extends ElementApplication
|
|
55
90
|
* @property {number} fontSize - The font size, in points
|
|
@@ -100,7 +135,7 @@ export class MarkdownUp extends ElementApplication {
|
|
|
100
135
|
|
|
101
136
|
/**
|
|
102
137
|
* The [Element Application main entry point]{@link
|
|
103
|
-
* https://craigahobbs.github.io/element-app/module-lib_app.ElementApplication.html#
|
|
138
|
+
* https://craigahobbs.github.io/element-app/module-lib_app.ElementApplication.html#main}.
|
|
104
139
|
*
|
|
105
140
|
* @override
|
|
106
141
|
* @returns {Object} [MainResult]{@link https://craigahobbs.github.io/element-app/module-lib_app.html#~MainResult}
|
|
@@ -122,6 +157,25 @@ export class MarkdownUp extends ElementApplication {
|
|
|
122
157
|
markdownTitle = getMarkdownTitle(markdownModel);
|
|
123
158
|
}
|
|
124
159
|
|
|
160
|
+
// Command?
|
|
161
|
+
let cmdElements = null;
|
|
162
|
+
if ('cmd' in this.params) {
|
|
163
|
+
// Display markdown?
|
|
164
|
+
if ('markdown' in this.params.cmd) {
|
|
165
|
+
cmdElements = {'html': 'div', 'attr': {'class': 'markdown'}, 'elem': {'text': text}};
|
|
166
|
+
|
|
167
|
+
// Help
|
|
168
|
+
} else if (this.params.cmd.help === 'Bar') {
|
|
169
|
+
cmdElements = new UserTypeElements(this.params).getElements(chartModel.types, `BarChart`);
|
|
170
|
+
} else if (this.params.cmd.help === 'Line') {
|
|
171
|
+
cmdElements = new UserTypeElements(this.params).getElements(chartModel.types, `LineChart`);
|
|
172
|
+
} else if (this.params.cmd.help === 'Table') {
|
|
173
|
+
cmdElements = new UserTypeElements(this.params).getElements(chartModel.types, `DataTable`);
|
|
174
|
+
} else {
|
|
175
|
+
cmdElements = new UserTypeElements(this.params).getElements(this.hashTypes, this.hashType);
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
|
|
125
179
|
// Helper function to create a cycle link
|
|
126
180
|
const linkCycle = (paramName, defaultValue, delta, fixed = null) => {
|
|
127
181
|
const value = paramName in this.params ? this.params[paramName] : defaultValue;
|
|
@@ -160,23 +214,30 @@ export class MarkdownUp extends ElementApplication {
|
|
|
160
214
|
};
|
|
161
215
|
|
|
162
216
|
// Render the text as Markdown
|
|
217
|
+
const chartOptions = {
|
|
218
|
+
'fontSize': 0.9 * (this.params !== null && 'fontSize' in this.params ? this.params.fontSize : this.fontSize),
|
|
219
|
+
url,
|
|
220
|
+
'variables': 'variables' in this.params ? this.params.variables : {},
|
|
221
|
+
'window': this.window
|
|
222
|
+
};
|
|
163
223
|
return {
|
|
164
224
|
'title': markdownTitle,
|
|
165
225
|
'elements': [
|
|
166
|
-
//
|
|
167
|
-
|
|
168
|
-
? null : this.helpElements(),
|
|
169
|
-
|
|
170
|
-
// Render markdown?
|
|
171
|
-
!('cmd' in this.params && 'markdown' in this.params.cmd)
|
|
172
|
-
? null : {'html': 'div', 'attr': {'class': 'markdown'}, 'elem': {'text': text}},
|
|
226
|
+
// Command?
|
|
227
|
+
cmdElements !== null ? cmdElements : null,
|
|
173
228
|
|
|
174
229
|
// Add a top hash ID, if necessary
|
|
175
|
-
|
|
230
|
+
cmdElements !== null || Object.keys(this.params).length === 0
|
|
176
231
|
? null : {'html': 'div', 'attr': {'id': encodeQueryString(this.params), 'style': 'display=none'}},
|
|
177
232
|
|
|
178
233
|
// Render the markdown
|
|
179
|
-
|
|
234
|
+
cmdElements !== null ? null : markdownElements(markdownModel, {
|
|
235
|
+
'codeBlocks': {
|
|
236
|
+
'bar-chart': (language, lines) => barChartCodeBlock(language, lines, chartOptions),
|
|
237
|
+
'data-table': (language, lines) => dataTableCodeBlock(language, lines, chartOptions),
|
|
238
|
+
'drawing': (language, lines) => drawingCodeBlock(language, lines, chartOptions),
|
|
239
|
+
'line-chart': (language, lines) => lineChartCodeBlock(language, lines, chartOptions)
|
|
240
|
+
},
|
|
180
241
|
'hashFn': (hashURL) => {
|
|
181
242
|
// Decode the hash params
|
|
182
243
|
const hashParams = decodeQueryString(hashURL.slice(1));
|
|
@@ -211,6 +272,11 @@ export class MarkdownUp extends ElementApplication {
|
|
|
211
272
|
'html': 'div',
|
|
212
273
|
'attr': {'class': 'menu'},
|
|
213
274
|
'elem': [
|
|
275
|
+
{
|
|
276
|
+
'html': 'a',
|
|
277
|
+
'attr': {'href': linkCommandToggle('markdown', 1), 'aria-label': 'Show Markdown'},
|
|
278
|
+
'elem': markdownSVGElements
|
|
279
|
+
},
|
|
214
280
|
{
|
|
215
281
|
'html': 'a',
|
|
216
282
|
'attr': {'href': linkCycle('fontSize', this.fontSize, 2), 'aria-label': 'Font size'},
|
|
@@ -223,12 +289,7 @@ export class MarkdownUp extends ElementApplication {
|
|
|
223
289
|
},
|
|
224
290
|
{
|
|
225
291
|
'html': 'a',
|
|
226
|
-
'attr': {'href': linkCommandToggle('
|
|
227
|
-
'elem': markdownSVGElements
|
|
228
|
-
},
|
|
229
|
-
{
|
|
230
|
-
'html': 'a',
|
|
231
|
-
'attr': {'href': linkCommandToggle('help', 1), 'aria-label': 'Help'},
|
|
292
|
+
'attr': {'href': linkCommandToggle('help', 'Help'), 'aria-label': 'Help'},
|
|
232
293
|
'elem': helpSVGElements
|
|
233
294
|
}
|
|
234
295
|
]
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"type": "module",
|
|
3
3
|
"name": "markdown-up",
|
|
4
|
-
"version": "1.
|
|
4
|
+
"version": "1.5.1",
|
|
5
5
|
"description": "JavaScript Markdown viewer application",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"markdown",
|
|
@@ -22,16 +22,17 @@
|
|
|
22
22
|
"test": "ava -v test/"
|
|
23
23
|
},
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"element-app": "~1.
|
|
26
|
-
"
|
|
27
|
-
"markdown-model": "~1.
|
|
28
|
-
"schema-markdown": "~1.
|
|
25
|
+
"element-app": "~1.1",
|
|
26
|
+
"markdown-charts": "~0.9",
|
|
27
|
+
"markdown-model": "~1.3",
|
|
28
|
+
"schema-markdown": "~1.1",
|
|
29
|
+
"schema-markdown-doc": "~1.2"
|
|
29
30
|
},
|
|
30
31
|
"devDependencies": {
|
|
31
32
|
"ava": "^4.0.0-rc.1",
|
|
32
33
|
"c8": "~7.10",
|
|
33
|
-
"eslint": "~8.
|
|
34
|
+
"eslint": "~8.4",
|
|
34
35
|
"jsdoc": "~3.6",
|
|
35
|
-
"jsdom": "~
|
|
36
|
+
"jsdom": "~19.0"
|
|
36
37
|
}
|
|
37
38
|
}
|