markdown-up 1.7.5 → 1.8.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.
package/README.md CHANGED
@@ -52,19 +52,74 @@ To view a different Markdown resource, set the application's
52
52
  (i.e., "http://127.0.0.1:8000#url=other.md").
53
53
 
54
54
 
55
- ### MarkdownUp Application Options
55
+ ## Dynamic Markdown Applications
56
+
57
+ Using MarkdownUp's "markdown-script" fenced code blocks, you can dynamically generate Markdown,
58
+ allowing you to build lightweight, client-rendered web applications with no HTML, no CSS, and a
59
+ single dependency (MarkdownUp). The "markdown-script" fenced code blocks are interpreted as the
60
+ [CalcScript programming language](https://craigahobbs.github.io/calc-script/language/).
61
+ In addition to generating Markdown, you can fetch text and JSON resources, create SVG drawings,
62
+ parse CSV, render data tables, draw line charts, and more. For more information, see
63
+ [the MarkdownUp Library](https://craigahobbs.github.io/markdown-up/library/) and
64
+ [the CalcScript Library](https://craigahobbs.github.io/calc-script/library/).
65
+
66
+ For example:
67
+
68
+ ```
69
+ # MarkdownUp Dynamic Markdown Example
70
+
71
+ ~~~ markdown-script
72
+ # Variable arguments
73
+ helloCount = if(vCount != null, vCount, 5)
74
+
75
+ # Constants
76
+ width = 140
77
+ height = 40
78
+ borderSize = 5
79
+ borderColor = 'blue'
80
+
81
+ # Render the more/less menu
82
+ markdownPrint( \
83
+ '', \
84
+ if(helloCount <= 1, 'Less', '[Less](#var.vCount=' + (helloCount - 1) + ')') + ' | ', \
85
+ '[More](#var.vCount=' + (helloCount + 1) + ')' \
86
+ )
87
+
88
+ # Render many hellos
89
+ ixHello = 0
90
+ helloLoop:
91
+ # Render the hello title
92
+ helloTitle = 'Hello #' + (ixHello + 1)
93
+ markdownPrint('', '## ' + helloTitle)
94
+
95
+ # Render the hello drawing
96
+ setDrawingSize(width, height)
97
+ drawStyle(borderColor, borderSize)
98
+ drawRect(0.5 * borderSize, 0.5 * borderSize, width - borderSize, height - borderSize)
99
+ drawTextStyle(0.67 * height, null, true)
100
+ drawText(helloTitle, 0.5 * width, 0.55 * height)
101
+
102
+ ixHello = ixHello + 1
103
+ jumpif (ixHello < helloCount) helloLoop
104
+ ~~~
105
+ ```
106
+
107
+ Click here to [see the example in action](https://craigahobbs.github.io/markdown-up/#url=DynamicMarkdownExample.md).
56
108
 
57
- The MarkdownUp application supports the following options:
58
109
 
59
- - **fontSize** - The default font size, in points
110
+ ### Links
60
111
 
61
- - **lineHeight** - The default line height, in em
112
+ - [Dynamic Markdown Examples](https://craigahobbs.github.io/#url=MarkdownUpApplications.md)
113
+ - [The CalcScript Language](https://craigahobbs.github.io/calc-script/language/)
114
+ - [The CalcScript Library](https://craigahobbs.github.io/calc-script/library/)
115
+ - [The MarkdownUp Library](https://craigahobbs.github.io/markdown-up/library/)
62
116
 
63
- - **markdownText** - The default Markdown text
64
117
 
65
- - **menu** - If false, the application menu is hidden
118
+ ## The MarkdownUp Package
66
119
 
67
- - **url** - The default Markdown resource URL
120
+ The [markdown-up package](https://www.npmjs.com/package/markdown-up) contains functions for parsing
121
+ CSV, manipulating data, and rendering tables and charts. For more information, refer to the
122
+ [MarkdownUp package documentation](https://craigahobbs.github.io/markdown-up/doc/).
68
123
 
69
124
 
70
125
  ## Development
package/lib/app.js CHANGED
@@ -7,20 +7,17 @@ import {MarkdownScriptRuntime, markdownScriptCodeBlock} from './script.js';
7
7
  import {decodeQueryString, encodeQueryString} from 'schema-markdown/lib/encode.js';
8
8
  import {getBaseURL, isRelativeURL, markdownElementsAsync} from 'markdown-model/lib/elements.js';
9
9
  import {getMarkdownTitle, parseMarkdown} from 'markdown-model/lib/parser.js';
10
- import {SchemaMarkdownParser} from 'schema-markdown/lib/parser.js';
11
- import {barChartCodeBlock} from './barChart.js';
12
- import {dataTableCodeBlock} from './dataTable.js';
13
10
  import {evaluateExpression} from 'calc-script/lib/runtime.js';
14
- import {lineChartCodeBlock} from './lineChart.js';
15
11
  import {markdownScriptFunctions} from './scriptLibrary.js';
16
12
  import {parseExpression} from 'calc-script/lib/parser.js';
13
+ import {parseSchemaMarkdown} from 'schema-markdown/lib/parser.js';
17
14
  import {renderElements} from 'element-model/lib/elementModel.js';
18
15
  import {schemaMarkdownDoc} from 'schema-markdown-doc/lib/schemaMarkdownDoc.js';
19
16
  import {validateType} from 'schema-markdown/lib/schema.js';
20
17
 
21
18
 
22
19
  // The application's hash parameter type model
23
- const markdownUpTypesSmd = `\
20
+ const markdownUpTypes = parseSchemaMarkdown(`\
24
21
  #
25
22
  # [MarkdownUp](https://craigahobbs.github.io/markdown-up/) is a Markdown viewer.
26
23
  #
@@ -60,8 +57,7 @@ union Command
60
57
 
61
58
  # Show the resource's Markdown text
62
59
  int(== 1) markdown
63
- `;
64
- const markdownUpTypes = new SchemaMarkdownParser(markdownUpTypesSmd).types;
60
+ `);
65
61
 
66
62
 
67
63
  /**
@@ -78,16 +74,6 @@ const markdownUpTypes = new SchemaMarkdownParser(markdownUpTypesSmd).types;
78
74
 
79
75
  /**
80
76
  * The MarkdownUp application
81
- *
82
- * @property {Object} window - The web browser window object
83
- * @property {?Object} params - The validated hash parameters object
84
- * @property {number} fontSize - The font size, in points
85
- * @property {number} lineHeight - The line height, in em
86
- * @property {?string} markdownText - The default Markdown text
87
- * @property {boolean} menu - If true, show the menu
88
- * @property {string} url - The default resource URL
89
- * @property {?function} runtimeWindowResize - The runtime-set window resize event listener function
90
- * @property {?number} runtimeTimeoutId - The runtime-set timeout ID
91
77
  */
92
78
  export class MarkdownUp {
93
79
  /**
@@ -110,8 +96,7 @@ export class MarkdownUp {
110
96
 
111
97
 
112
98
  /**
113
- * Run the application. This method calls the render method and subscribes to hash parameter
114
- * changes to re-render.
99
+ * Run the application
115
100
  */
116
101
  async run() {
117
102
  await this.render();
@@ -119,9 +104,6 @@ export class MarkdownUp {
119
104
  }
120
105
 
121
106
 
122
- /**
123
- * Render the application
124
- */
125
107
  async render() {
126
108
  // Parse the hash parameters and render the application element model
127
109
  let result;
@@ -197,11 +179,6 @@ export class MarkdownUp {
197
179
  }
198
180
 
199
181
 
200
- /**
201
- * Parse and validate the hash parameters
202
- *
203
- * @param {?string} [paramString = null] - Optional parameter string for testing
204
- */
205
182
  updateParams(paramString = null) {
206
183
  // Clear, then validate the hash parameters (may throw)
207
184
  this.params = null;
@@ -241,11 +218,6 @@ export class MarkdownUp {
241
218
  }
242
219
 
243
220
 
244
- /**
245
- * The application's main entry point
246
- *
247
- * @returns {Object}
248
- */
249
221
  async main() {
250
222
  // Help?
251
223
  if ('cmd' in this.params && 'help' in this.params.cmd) {
@@ -307,9 +279,6 @@ export class MarkdownUp {
307
279
  // Render the markdown
308
280
  await markdownElementsAsync(markdownModel, {
309
281
  'codeBlocks': {
310
- 'bar-chart': (codeBlock) => barChartCodeBlock(codeBlock, scriptOptions),
311
- 'data-table': (codeBlock) => dataTableCodeBlock(codeBlock, scriptOptions),
312
- 'line-chart': (codeBlock) => lineChartCodeBlock(codeBlock, scriptOptions),
313
282
  'markdown-script': (codeBlock) => markdownScriptCodeBlock(codeBlock, scriptOptions)
314
283
  },
315
284
  'urlFn': (urlRaw) => this.modifyURL(urlRaw, url),