markdown-up 2.3.5 → 2.3.6

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 +56 -56
  2. package/package.json +1 -1
package/lib/app.js CHANGED
@@ -194,17 +194,10 @@ export class MarkdownUp {
194
194
  return;
195
195
  }
196
196
 
197
- // URL hash ID?
198
- const hashId = getHashID(this.window.location.hash);
199
- if (!isError && hashId !== null) {
200
- // Special "top" hash ID?
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
 
@@ -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 hash ID
483
+ // Encode hash parameters with a header ID
491
484
  const paramString = encodeQueryString({...this.params, ...hashParams});
492
- const hashID = getHashID(url);
493
- return `#${paramString}${hashID !== null && paramString !== '' ? '&' : ''}${hashID !== null ? hashID : ''}`;
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
- return !this.menu ? null : [
507
- {
508
- 'html': 'div',
509
- 'attr': {'class': 'menu-burger'},
510
- 'elem': this.menuValueToggle('menu', {
511
- 'size': 32,
512
- 'noCheck': true,
513
- 'path': 'M3,5 L21,5 M3,12 L21,12 M3,19 L21,19'
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
 
@@ -643,13 +643,13 @@ export class MarkdownUp {
643
643
  }
644
644
 
645
645
 
646
- // Get a URL's hash ID
647
- function getHashID(url) {
648
- const matchId = url.match(rHashId);
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 rHashId = /[#&]([^=]+)$/;
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.3.5",
4
+ "version": "2.3.6",
5
5
  "description": "MarkdownUp is a Markdown viewer",
6
6
  "keywords": [
7
7
  "markdown",