markdown-up 2.3.5 → 2.4.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/lib/app.js +67 -67
- package/package.json +3 -3
package/lib/app.js
CHANGED
|
@@ -33,6 +33,9 @@ struct MarkdownUp
|
|
|
33
33
|
# Variable expressions
|
|
34
34
|
optional string{} var
|
|
35
35
|
|
|
36
|
+
# Optional command
|
|
37
|
+
optional MarkdownUpView view
|
|
38
|
+
|
|
36
39
|
|
|
37
40
|
# The MarkdownUp local storage JSON schema
|
|
38
41
|
struct MarkdownUpLocal
|
|
@@ -50,9 +53,6 @@ struct MarkdownUpLocal
|
|
|
50
53
|
# The MarkdownUp session storage JSON schema
|
|
51
54
|
struct MarkdownUpSession
|
|
52
55
|
|
|
53
|
-
# Optional command
|
|
54
|
-
optional MarkdownUpView view
|
|
55
|
-
|
|
56
56
|
# If set, the menu is expanded (default is collapsed)
|
|
57
57
|
optional int(== 1) menu
|
|
58
58
|
|
|
@@ -194,17 +194,10 @@ export class MarkdownUp {
|
|
|
194
194
|
return;
|
|
195
195
|
}
|
|
196
196
|
|
|
197
|
-
//
|
|
198
|
-
|
|
199
|
-
if (!isError &&
|
|
200
|
-
|
|
201
|
-
if (hashId === 'top' && this.window.document.getElementById(this.window.location.hash.slice(1)) === null) {
|
|
202
|
-
this.window.scrollTo(0, 0);
|
|
203
|
-
} else {
|
|
204
|
-
// Re-navigate to scroll to the hash ID since it was just rendered. The re-render is
|
|
205
|
-
// short-circuited by the unchanged hash param check above.
|
|
206
|
-
this.window.location.href = this.window.location.hash;
|
|
207
|
-
}
|
|
197
|
+
// If there is a header ID, re-navigate to scroll to the header ID since it was just rendered.
|
|
198
|
+
// The re-render is short-circuited by the unchanged hash param check above.
|
|
199
|
+
if (!isError && getHeaderId(this.window.location.hash) !== null) {
|
|
200
|
+
this.window.location.href = this.window.location.hash;
|
|
208
201
|
}
|
|
209
202
|
}
|
|
210
203
|
|
|
@@ -273,7 +266,7 @@ export class MarkdownUp {
|
|
|
273
266
|
|
|
274
267
|
async main() {
|
|
275
268
|
// Help?
|
|
276
|
-
if (this.
|
|
269
|
+
if (this.params.view === 'help') {
|
|
277
270
|
return {
|
|
278
271
|
'title': 'MarkdownUp',
|
|
279
272
|
'elements': [
|
|
@@ -337,7 +330,7 @@ export class MarkdownUp {
|
|
|
337
330
|
const markdownTitle = getMarkdownTitle(markdownModel);
|
|
338
331
|
|
|
339
332
|
// Display the Markdown?
|
|
340
|
-
if (this.
|
|
333
|
+
if (this.params.view === 'markdown') {
|
|
341
334
|
return {
|
|
342
335
|
'title': markdownTitle,
|
|
343
336
|
'elements': [
|
|
@@ -487,10 +480,10 @@ export class MarkdownUp {
|
|
|
487
480
|
hashParams.url = `${getBaseURL(resourceURL)}${hashParams.url}`;
|
|
488
481
|
}
|
|
489
482
|
|
|
490
|
-
// Encode hash parameters with a
|
|
483
|
+
// Encode hash parameters with a header ID
|
|
491
484
|
const paramString = encodeQueryString({...this.params, ...hashParams});
|
|
492
|
-
const
|
|
493
|
-
return `#${paramString}${
|
|
485
|
+
const headerId = getHeaderId(url);
|
|
486
|
+
return `#${paramString}${headerId !== null && paramString !== '' ? '&' : ''}${headerId !== null ? headerId : ''}`;
|
|
494
487
|
}
|
|
495
488
|
|
|
496
489
|
// Relative URL?
|
|
@@ -503,45 +496,52 @@ export class MarkdownUp {
|
|
|
503
496
|
|
|
504
497
|
|
|
505
498
|
burgerElements() {
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
'
|
|
512
|
-
'
|
|
513
|
-
'
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
// Popup menu
|
|
518
|
-
!('menu' in this.paramsSession) ? null : {
|
|
519
|
-
'html': 'div',
|
|
520
|
-
'attr': {'class': 'menu'},
|
|
521
|
-
'elem': [
|
|
522
|
-
this.menuViewToggle('markdown', {
|
|
523
|
-
'path': 'M4,2 L20,2 L20,22 L4,22 Z',
|
|
524
|
-
'path2': 'M7,7.5 L17,7.5 M7,12 L17,12 M7,16.5 L17,16.5'
|
|
525
|
-
}),
|
|
526
|
-
this.menuValueToggle('darkMode', {
|
|
527
|
-
'path': 'M16,3 A10,10,0,1,1,3,18 A14,14,0,0,0,17,3'
|
|
528
|
-
}, true),
|
|
529
|
-
this.menuValueCycle('fontSize', this.fontSize, 2, {
|
|
530
|
-
'path': 'M4,22 L10,2 L14,2 L20,22 M6,14 L18,14',
|
|
531
|
-
'strokeWidth': 4
|
|
532
|
-
}),
|
|
533
|
-
this.menuValueCycle('lineHeight', this.lineHeight, 0.2, {
|
|
534
|
-
'path2': 'M2,3 L22,3 M2,9 L22,9 M2,15 L22,15 M2,21 L22,21'
|
|
535
|
-
}),
|
|
536
|
-
this.menuValueToggle('debug', {
|
|
537
|
-
'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 ' +
|
|
538
|
-
'M15,9 L20,6 M15,12 L21,12 M15,15 L20,18'
|
|
539
|
-
}),
|
|
540
|
-
this.menuViewToggle('help', {
|
|
541
|
-
'path': 'M7,9 L7,4 L17,4 L17,12 L12,12 L12,16 M12,19 L12,22'
|
|
499
|
+
const paramString = encodeQueryString(this.params);
|
|
500
|
+
const topHeaderId = `${paramString}${paramString !== '' ? '&' : ''}_top`;
|
|
501
|
+
return [
|
|
502
|
+
!this.menu ? null : [
|
|
503
|
+
{
|
|
504
|
+
'html': 'div',
|
|
505
|
+
'attr': {'class': 'menu-burger'},
|
|
506
|
+
'elem': this.menuValueToggle('menu', {
|
|
507
|
+
'size': 32,
|
|
508
|
+
'noCheck': true,
|
|
509
|
+
'path': 'M3,5 L21,5 M3,12 L21,12 M3,19 L21,19'
|
|
542
510
|
})
|
|
543
|
-
|
|
544
|
-
|
|
511
|
+
},
|
|
512
|
+
|
|
513
|
+
// Popup menu
|
|
514
|
+
!('menu' in this.paramsSession) ? null : {
|
|
515
|
+
'html': 'div',
|
|
516
|
+
'attr': {'class': 'menu'},
|
|
517
|
+
'elem': [
|
|
518
|
+
this.menuViewToggle('markdown', {
|
|
519
|
+
'path': 'M4,2 L20,2 L20,22 L4,22 Z',
|
|
520
|
+
'path2': 'M7,7.5 L17,7.5 M7,12 L17,12 M7,16.5 L17,16.5'
|
|
521
|
+
}),
|
|
522
|
+
this.menuValueToggle('darkMode', {
|
|
523
|
+
'path': 'M16,3 A10,10,0,1,1,3,18 A14,14,0,0,0,17,3'
|
|
524
|
+
}, true),
|
|
525
|
+
this.menuValueCycle('fontSize', this.fontSize, 2, {
|
|
526
|
+
'path': 'M4,22 L10,2 L14,2 L20,22 M6,14 L18,14',
|
|
527
|
+
'strokeWidth': 4
|
|
528
|
+
}),
|
|
529
|
+
this.menuValueCycle('lineHeight', this.lineHeight, 0.2, {
|
|
530
|
+
'path2': 'M2,3 L22,3 M2,9 L22,9 M2,15 L22,15 M2,21 L22,21'
|
|
531
|
+
}),
|
|
532
|
+
this.menuValueToggle('debug', {
|
|
533
|
+
'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 ' +
|
|
534
|
+
'M15,9 L20,6 M15,12 L21,12 M15,15 L20,18'
|
|
535
|
+
}),
|
|
536
|
+
this.menuViewToggle('help', {
|
|
537
|
+
'path': 'M7,9 L7,4 L17,4 L17,12 L12,12 L12,16 M12,19 L12,22'
|
|
538
|
+
})
|
|
539
|
+
]
|
|
540
|
+
}
|
|
541
|
+
],
|
|
542
|
+
|
|
543
|
+
// The top header ID
|
|
544
|
+
{'html': 'div', 'attr': {'id': topHeaderId, 'style': 'display=none; position: absolute; top: 0;'}}
|
|
545
545
|
];
|
|
546
546
|
}
|
|
547
547
|
|
|
@@ -566,16 +566,16 @@ export class MarkdownUp {
|
|
|
566
566
|
|
|
567
567
|
|
|
568
568
|
menuViewToggle(viewValue, icon) {
|
|
569
|
-
icon.checked = this.
|
|
569
|
+
icon.checked = this.params.view === viewValue;
|
|
570
570
|
return this.menuButton(
|
|
571
571
|
() => {
|
|
572
|
-
|
|
573
|
-
|
|
572
|
+
const params = {...this.params};
|
|
573
|
+
if (params.view === viewValue) {
|
|
574
|
+
delete params.view;
|
|
574
575
|
} else {
|
|
575
|
-
|
|
576
|
+
params.view = viewValue;
|
|
576
577
|
}
|
|
577
|
-
this.window.
|
|
578
|
-
this.render(true);
|
|
578
|
+
this.window.location.href = `#${encodeQueryString(params)}`;
|
|
579
579
|
},
|
|
580
580
|
icon
|
|
581
581
|
);
|
|
@@ -643,13 +643,13 @@ export class MarkdownUp {
|
|
|
643
643
|
}
|
|
644
644
|
|
|
645
645
|
|
|
646
|
-
// Get a URL's
|
|
647
|
-
function
|
|
648
|
-
const matchId = url.match(
|
|
646
|
+
// Get a URL's header ID
|
|
647
|
+
function getHeaderId(url) {
|
|
648
|
+
const matchId = url.match(rHeaderId);
|
|
649
649
|
return matchId !== null ? matchId[1] : null;
|
|
650
650
|
}
|
|
651
651
|
|
|
652
|
-
const
|
|
652
|
+
const rHeaderId = /[#&]([^=]+)$/;
|
|
653
653
|
|
|
654
654
|
|
|
655
655
|
// Test if a URL is relative
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"type": "module",
|
|
3
3
|
"name": "markdown-up",
|
|
4
|
-
"version": "2.
|
|
4
|
+
"version": "2.4.0",
|
|
5
5
|
"description": "MarkdownUp is a Markdown viewer",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"markdown",
|
|
@@ -30,8 +30,8 @@
|
|
|
30
30
|
},
|
|
31
31
|
"devDependencies": {
|
|
32
32
|
"c8": "~8.0",
|
|
33
|
-
"eslint": "~8.
|
|
33
|
+
"eslint": "~8.54",
|
|
34
34
|
"jsdoc": "~4.0",
|
|
35
|
-
"jsdom": "~
|
|
35
|
+
"jsdom": "~23.0"
|
|
36
36
|
}
|
|
37
37
|
}
|