markdown-up 1.8.8 → 1.8.9

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
@@ -3,14 +3,19 @@
3
3
  [![npm](https://img.shields.io/npm/v/markdown-up)](https://www.npmjs.com/package/markdown-up)
4
4
  [![GitHub](https://img.shields.io/github/license/craigahobbs/markdown-up)](https://github.com/craigahobbs/markdown-up/blob/main/LICENSE)
5
5
 
6
- [MarkdownUp](https://craigahobbs.github.io/markdown-up/)
7
- is a Markdown viewer.
6
+ [MarkdownUp](https://craigahobbs.github.io/markdown-up/) is a Markdown viewer.
7
+
8
+
9
+ ## Links
10
+
11
+ - [MarkdownUp Application](https://craigahobbs.github.io/markdown-up/)
12
+ - [Source code](https://github.com/craigahobbs/markdown-up)
8
13
 
9
14
 
10
15
  ## View Local Markdown Files
11
16
 
12
17
  To view local Markdown files, use the
13
- [MarkdownUp launcher](https://pypi.org/project/markdown-up/)
18
+ [MarkdownUp launcher](https://github.com/craigahobbs/markdown-up-py#readme)
14
19
  from a terminal prompt:
15
20
 
16
21
  ~~~
@@ -142,8 +147,8 @@ CSV, manipulating data, and rendering tables and charts. For more information, r
142
147
 
143
148
  ## Development
144
149
 
145
- MarkdownUp is developed using [javascript-build](https://github.com/craigahobbs/javascript-build#readme)
146
- and it was started using [javascript-template](https://github.com/craigahobbs/javascript-template#readme):
150
+ This package is developed using [javascript-build](https://github.com/craigahobbs/javascript-build#readme).
151
+ It was started using [javascript-template](https://github.com/craigahobbs/javascript-template#readme) as follows:
147
152
 
148
153
  ~~~
149
154
  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
@@ -268,8 +268,8 @@ export class MarkdownUp {
268
268
  return {
269
269
  'title': 'MarkdownUp',
270
270
  'elements': [
271
- schemaMarkdownDoc(markdownUpTypes, 'MarkdownUp', {'params': encodeQueryString(this.params)}),
272
- this.burgerElements()
271
+ this.burgerElements(),
272
+ schemaMarkdownDoc(markdownUpTypes, 'MarkdownUp', {'params': encodeQueryString(this.params)})
273
273
  ]
274
274
  };
275
275
  }
@@ -332,8 +332,8 @@ export class MarkdownUp {
332
332
  return {
333
333
  'title': markdownTitle,
334
334
  'elements': [
335
- {'html': 'div', 'attr': {'class': 'markdown'}, 'elem': {'text': markdownText}},
336
- this.burgerElements()
335
+ this.burgerElements(),
336
+ {'html': 'div', 'attr': {'class': 'markdown'}, 'elem': {'text': markdownText}}
337
337
  ]
338
338
  };
339
339
  }
@@ -342,6 +342,9 @@ export class MarkdownUp {
342
342
  const result = {
343
343
  'title': markdownTitle,
344
344
  'elements': [
345
+ // Menu "burger"
346
+ this.burgerElements(),
347
+
345
348
  // Add a top hash ID, if necessary
346
349
  Object.keys(this.params).length === 0
347
350
  ? null : {'html': 'div', 'attr': {'id': encodeQueryString(this.params), 'style': 'display=none'}},
@@ -353,10 +356,7 @@ export class MarkdownUp {
353
356
  },
354
357
  'urlFn': (urlRaw) => this.modifyURL(urlRaw, url),
355
358
  'headerIds': true
356
- }),
357
-
358
- // Popup menu burger
359
- this.burgerElements()
359
+ })
360
360
  ]
361
361
  };
362
362
 
@@ -444,12 +444,18 @@ export class MarkdownUp {
444
444
  }
445
445
 
446
446
  // Reset the runtime and render
447
- const {isDocumentReset, windowLocation} = runtime;
448
- const documentElements = [
449
- runtime.resetElements(),
450
- isDocumentReset ? this.burgerElements() : null
451
- ];
452
- renderElements(this.window.document.body, documentElements, isDocumentReset);
447
+ const elements = runtime.resetElements();
448
+ if (elements !== null) {
449
+ const {body} = this.window.document;
450
+ if (runtime.documentReset === null) {
451
+ renderElements(body, [this.burgerElements(), elements]);
452
+ } else {
453
+ while (body.lastChild !== null && body.lastChild.id !== runtime.documentReset) {
454
+ body.lastChild.remove();
455
+ }
456
+ renderElements(body, [elements], false);
457
+ }
458
+ }
453
459
 
454
460
  // Focus?
455
461
  if (runtime.documentFocus !== null) {
@@ -458,8 +464,8 @@ export class MarkdownUp {
458
464
 
459
465
  // Navigate?
460
466
  // Note: This is done after render since it may have no effect (in which case we want to render).
461
- if (windowLocation !== null) {
462
- this.window.location.href = windowLocation;
467
+ if (runtime.windowLocation !== null) {
468
+ this.window.location.href = runtime.windowLocation;
463
469
  }
464
470
 
465
471
  // Reset the runtime
package/lib/script.js CHANGED
@@ -111,12 +111,12 @@ const pixelsPerPoint = 4 / 3;
111
111
  *
112
112
  * @property {Object} options - The [markdown-script options]{@link module:lib/script~MarkdownScriptOptions}
113
113
  * @property {?Object[]} elements - The runtime-generated element model
114
- * @property {?string} documentFocus - The the runtime-set element ID to set input focus
115
- * @property {?string} documentTitle - The the runtime-set document title
116
- * @property {boolean} isDocumentReset - If true, the runtime requested a document-reset
117
- * @property {?string} windowLocation - The the runtime-set document location
118
- * @property {?function} windowResize - The the runtime-set resize callback
119
- * @property {?Array} windowTimeout - The the runtime-set timeout args (callback, delay)
114
+ * @property {?string} documentFocus - The runtime-set input-focus element ID
115
+ * @property {?string} documentReset - The runtime-set document-reset element ID
116
+ * @property {?string} documentTitle - The runtime-set document title
117
+ * @property {?string} windowLocation - The runtime-set document location
118
+ * @property {?function} windowResize - The runtime-set resize callback
119
+ * @property {?Array} windowTimeout - The runtime-set timeout args (callback, delay)
120
120
  *
121
121
  * @ignore
122
122
  */
@@ -128,8 +128,8 @@ export class MarkdownScriptRuntime {
128
128
  this.options = options;
129
129
  this.elements = null;
130
130
  this.documentFocus = null;
131
+ this.documentReset = null;
131
132
  this.documentTitle = null;
132
- this.isDocumentReset = false;
133
133
  this.windowLocation = null;
134
134
  this.windowResize = null;
135
135
  this.windowTimeout = null;
@@ -160,8 +160,8 @@ export class MarkdownScriptRuntime {
160
160
  // Reset the runtime state
161
161
  reset() {
162
162
  this.documentFocus = null;
163
+ this.documentReset = null;
163
164
  this.documentTitle = null;
164
- this.isDocumentReset = false;
165
165
  this.windowLocation = null;
166
166
  this.windowResize = null;
167
167
  this.windowTimeout = null;
@@ -144,14 +144,6 @@ export const markdownScriptFunctions = {
144
144
  // Document functions
145
145
  //
146
146
 
147
- // $function: documentReset
148
- // $group: Document
149
- // $doc: Reset the document. This is useful within callback functions that re-render the document.
150
- 'documentReset': (unused, options) => {
151
- const {runtime} = options;
152
- runtime.isDocumentReset = true;
153
- },
154
-
155
147
  // $function: documentURL
156
148
  // $group: Document
157
149
  // $doc: Fix-up relative URLs
@@ -196,6 +188,15 @@ export const markdownScriptFunctions = {
196
188
  runtime.documentFocus = id;
197
189
  },
198
190
 
191
+ // $function: setDocumentReset
192
+ // $group: Document
193
+ // $doc: Set the document reset element
194
+ // $arg id: The element ID
195
+ 'setDocumentReset': ([id], options) => {
196
+ const {runtime} = options;
197
+ runtime.documentReset = id;
198
+ },
199
+
199
200
  // $function: setDocumentTitle
200
201
  // $group: Document
201
202
  // $doc: Set the document title
@@ -220,9 +221,9 @@ export const markdownScriptFunctions = {
220
221
  // $arg callback: The window resize callback function
221
222
  'setWindowResize': ([callback], options) => {
222
223
  const {runtime} = options;
223
- runtime.windowResize = () => {
224
+ runtime.windowResize = async () => {
224
225
  options.statementCount = 0;
225
- callback([], options);
226
+ await callback([], options);
226
227
  options.runtimeUpdateFn();
227
228
  };
228
229
  },
@@ -235,9 +236,9 @@ export const markdownScriptFunctions = {
235
236
  'setWindowTimeout': ([callback, delay], options) => {
236
237
  const {runtime} = options;
237
238
  runtime.windowTimeout = [
238
- () => {
239
+ async () => {
239
240
  options.statementCount = 0;
240
- callback([], options);
241
+ await callback([], options);
241
242
  options.runtimeUpdateFn();
242
243
  },
243
244
  delay
@@ -387,12 +388,13 @@ export const markdownScriptFunctions = {
387
388
  'drawOnClick': ([callback], options) => {
388
389
  const {runtime} = options;
389
390
  const svg = runtime.setDrawing();
390
- const clickElement = svg.elem.length === 0 ? svg : svg.elem[svg.elem.length - 1];
391
+ const clickElement = (svg.elem.length === 0 ? svg : svg.elem[svg.elem.length - 1]);
392
+ clickElement.attr.style = 'cursor: pointer; user-select: none;';
391
393
  clickElement.callback = (element) => {
392
- element.addEventListener('click', (event) => {
394
+ element.addEventListener('click', async (event) => {
393
395
  const boundingRect = event.target.ownerSVGElement.getBoundingClientRect();
394
396
  options.statementCount = 0;
395
- callback([event.clientX - boundingRect.left, event.clientY - boundingRect.top], options);
397
+ await callback([event.clientX - boundingRect.left, event.clientY - boundingRect.top], options);
396
398
  options.runtimeUpdateFn();
397
399
  });
398
400
  };
@@ -714,7 +716,7 @@ function elementModelWrapCallbacks(elements, options) {
714
716
  elements.callback = (element) => {
715
717
  // On element render, add a listener for each event
716
718
  for (const [elementEvent, elementEventCallback] of Object.entries(elementEvents)) {
717
- element.addEventListener(elementEvent, (event) => {
719
+ element.addEventListener(elementEvent, async (event) => {
718
720
  // Determine the event callback args
719
721
  const eventArgs = [];
720
722
  if (elementEvent === 'keydown' || elementEvent === 'keypress' || elementEvent === 'keyup') {
@@ -723,7 +725,7 @@ function elementModelWrapCallbacks(elements, options) {
723
725
 
724
726
  // Call the event handler
725
727
  options.statementCount = 0;
726
- elementEventCallback(eventArgs, options);
728
+ await elementEventCallback(eventArgs, options);
727
729
  options.runtimeUpdateFn();
728
730
  });
729
731
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "type": "module",
3
3
  "name": "markdown-up",
4
- "version": "1.8.8",
4
+ "version": "1.8.9",
5
5
  "description": "MarkdownUp is a Markdown viewer",
6
6
  "keywords": [
7
7
  "markdown",
@@ -31,7 +31,7 @@
31
31
  "devDependencies": {
32
32
  "ava": "~5.1",
33
33
  "c8": "~7.12",
34
- "eslint": "~8.28",
34
+ "eslint": "~8.31",
35
35
  "jsdoc": "~4.0",
36
36
  "jsdom": "~20.0"
37
37
  }