markdown-up 1.4.0 → 1.5.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.
Files changed (2) hide show
  1. package/lib/app.js +62 -14
  2. package/package.json +4 -3
package/lib/app.js CHANGED
@@ -4,9 +4,11 @@
4
4
  /** @module lib/app */
5
5
 
6
6
  import {ElementApplication, encodeHashID, getHashID} from 'element-app/lib/app.js';
7
+ import {barChartCodeBlock, dataTableCodeBlock, lineChartCodeBlock} from 'markdown-charts/lib/codeBlock.js';
7
8
  import {decodeQueryString, encodeQueryString} from 'schema-markdown/lib/encode.js';
8
9
  import {getBaseURL, isRelativeURL, markdownElements} from 'markdown-model/lib/elements.js';
9
10
  import {UserTypeElements} from 'schema-markdown-doc/lib/userTypeElements.js';
11
+ import {chartModel} from 'markdown-charts/lib/model.js';
10
12
  import {getMarkdownTitle} from 'markdown-model/lib/markdownModel.js';
11
13
  import {parseMarkdown} from 'markdown-model/lib/parser.js';
12
14
 
@@ -39,14 +41,38 @@ struct MarkdownUp
39
41
  # The line height
40
42
  optional int(>= 1, <= 2) lineHeight
41
43
 
44
+ # Variable collection
45
+ optional FieldValue{len > 0} variables
46
+
47
+
48
+ # Field value union
49
+ union FieldValue
50
+
51
+ # A datetime value
52
+ datetime(nullable) datetime
53
+
54
+ # A number value
55
+ float(nullable) number
56
+
57
+ # A string value
58
+ string(nullable) string
59
+
60
+
42
61
  # Application command union
43
62
  union Command
44
63
 
45
64
  # Display the application's hash parameter documentation
46
- int(== 1) help
65
+ HelpType help
47
66
 
48
67
  # Show the URL's Markdown text
49
68
  int(== 1) markdown
69
+
70
+ # Help type enum
71
+ enum HelpType
72
+ Help
73
+ Bar
74
+ Line
75
+ Table
50
76
  `;
51
77
 
52
78
 
@@ -112,13 +138,6 @@ export class MarkdownUp extends ElementApplication {
112
138
  * @returns {Object} [MainResult]{@link https://craigahobbs.github.io/element-app/module-lib_app.html#~MainResult}
113
139
  */
114
140
  async main() {
115
- // Help?
116
- if ('cmd' in this.params && 'help' in this.params.cmd) {
117
- return {
118
- 'elements': new UserTypeElements(this.params).getElements(this.hashTypes, this.hashType)
119
- };
120
- }
121
-
122
141
  // Load the text resource
123
142
  const url = 'url' in this.params ? this.params.url : this.url;
124
143
  let text = null;
@@ -135,6 +154,25 @@ export class MarkdownUp extends ElementApplication {
135
154
  markdownTitle = getMarkdownTitle(markdownModel);
136
155
  }
137
156
 
157
+ // Command?
158
+ let cmdElements = null;
159
+ if ('cmd' in this.params) {
160
+ // Display markdown?
161
+ if ('markdown' in this.params.cmd) {
162
+ cmdElements = {'html': 'div', 'attr': {'class': 'markdown'}, 'elem': {'text': text}};
163
+
164
+ // Help
165
+ } else if (this.params.cmd.help === 'Bar') {
166
+ cmdElements = new UserTypeElements(this.params).getElements(chartModel.types, `BarChart`);
167
+ } else if (this.params.cmd.help === 'Line') {
168
+ cmdElements = new UserTypeElements(this.params).getElements(chartModel.types, `LineChart`);
169
+ } else if (this.params.cmd.help === 'Table') {
170
+ cmdElements = new UserTypeElements(this.params).getElements(chartModel.types, `DataTable`);
171
+ } else {
172
+ cmdElements = new UserTypeElements(this.params).getElements(this.hashTypes, this.hashType);
173
+ }
174
+ }
175
+
138
176
  // Helper function to create a cycle link
139
177
  const linkCycle = (paramName, defaultValue, delta, fixed = null) => {
140
178
  const value = paramName in this.params ? this.params[paramName] : defaultValue;
@@ -173,19 +211,29 @@ export class MarkdownUp extends ElementApplication {
173
211
  };
174
212
 
175
213
  // Render the text as Markdown
214
+ const chartOptions = {
215
+ 'fontSize': 0.9 * (this.params !== null && 'fontSize' in this.params ? this.params.fontSize : this.fontSize),
216
+ url,
217
+ 'variables': 'variables' in this.params ? this.params.variables : {},
218
+ 'window': this.window
219
+ };
176
220
  return {
177
221
  'title': markdownTitle,
178
222
  'elements': [
179
- // Render markdown?
180
- !('cmd' in this.params && 'markdown' in this.params.cmd)
181
- ? null : {'html': 'div', 'attr': {'class': 'markdown'}, 'elem': {'text': text}},
223
+ // Command?
224
+ cmdElements !== null ? cmdElements : null,
182
225
 
183
226
  // Add a top hash ID, if necessary
184
- 'cmd' in this.params || Object.keys(this.params).length === 0
227
+ cmdElements !== null || Object.keys(this.params).length === 0
185
228
  ? null : {'html': 'div', 'attr': {'id': encodeQueryString(this.params), 'style': 'display=none'}},
186
229
 
187
230
  // Render the markdown
188
- 'cmd' in this.params ? null : markdownElements(markdownModel, {
231
+ cmdElements !== null ? null : markdownElements(markdownModel, {
232
+ 'codeBlocks': {
233
+ 'bar-chart': (language, lines) => barChartCodeBlock(language, lines, chartOptions),
234
+ 'data-table': (language, lines) => dataTableCodeBlock(language, lines, chartOptions),
235
+ 'line-chart': (language, lines) => lineChartCodeBlock(language, lines, chartOptions)
236
+ },
189
237
  'hashFn': (hashURL) => {
190
238
  // Decode the hash params
191
239
  const hashParams = decodeQueryString(hashURL.slice(1));
@@ -237,7 +285,7 @@ export class MarkdownUp extends ElementApplication {
237
285
  },
238
286
  {
239
287
  'html': 'a',
240
- 'attr': {'href': linkCommandToggle('help', 1), 'aria-label': 'Help'},
288
+ 'attr': {'href': linkCommandToggle('help', 'Help'), 'aria-label': 'Help'},
241
289
  'elem': helpSVGElements
242
290
  }
243
291
  ]
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "type": "module",
3
3
  "name": "markdown-up",
4
- "version": "1.4.0",
4
+ "version": "1.5.0",
5
5
  "description": "JavaScript Markdown viewer application",
6
6
  "keywords": [
7
7
  "markdown",
@@ -23,6 +23,7 @@
23
23
  },
24
24
  "dependencies": {
25
25
  "element-app": "~1.1",
26
+ "markdown-charts": "~0.9",
26
27
  "markdown-model": "~1.3",
27
28
  "schema-markdown": "~1.1",
28
29
  "schema-markdown-doc": "~1.2"
@@ -30,8 +31,8 @@
30
31
  "devDependencies": {
31
32
  "ava": "^4.0.0-rc.1",
32
33
  "c8": "~7.10",
33
- "eslint": "~8.3",
34
+ "eslint": "~8.4",
34
35
  "jsdoc": "~3.6",
35
- "jsdom": "~18.1"
36
+ "jsdom": "~19.0"
36
37
  }
37
38
  }