11const MarkdownReader = {
22 template : `<div v-html="html"></div>` ,
3- props : [ "file" , "fragment " ] ,
3+ props : [ "file" , "hash " ] ,
44 data : function ( ) {
55 return {
66 html : "" ,
@@ -12,27 +12,31 @@ const MarkdownReader = {
1212 this . setDocument ( ) ;
1313 this . loadFile ( file )
1414 . then ( ( ) => {
15- this . scrollToFragment ( this . fragment ) ;
15+ this . scrollToHash ( this . hash ) ;
1616 } ) ;
1717 } ,
18- 'fragment ' : function ( fragment ) {
19- this . scrollToFragment ( fragment ) ;
18+ 'hash ' : function ( hash ) {
19+ this . scrollToHash ( hash ) ;
2020 }
2121 } ,
2222 created : function ( ) {
2323 this . setDocument ( ) ;
2424 this . loadFile ( this . file )
2525 . then ( ( ) => {
26- this . scrollToFragment ( this . fragment ) ;
26+ this . scrollToHash ( this . hash ) ;
2727 } ) ;
2828 } ,
2929 methods : {
30- scrollToFragment : function ( fragment ) {
31- const fragmentElement = document . getElementById ( fragment ) ;
32- if ( fragmentElement )
33- fragmentElement . scrollIntoView ( ) ;
34- else
35- window . scrollTo ( 0 , 0 ) ;
30+ scrollToHash : function ( hash ) {
31+ if ( hash ) {
32+ const fragmentElement = document . getElementById ( hash . substring ( "#" . length ) ) ;
33+ if ( fragmentElement ) {
34+ fragmentElement . scrollIntoView ( ) ;
35+ return ;
36+ }
37+ }
38+
39+ window . scrollTo ( 0 , 0 ) ;
3640 } ,
3741 setDocument : function ( ) {
3842 if ( this . $route . params . document ) {
@@ -51,7 +55,7 @@ const MarkdownReader = {
5155
5256 showdown . extension ( 'header-anchors' , ( ) => {
5357
54- var ancTpl = '$1<a id="user-content-$3" class="anchor" href="#' + this . $route . params . document + '/ $3" aria-hidden="true">#</a> $4';
58+ var ancTpl = '$1<a id="user-content-$3" class="anchor" href="#$3" aria-hidden="true">#</a> $4' ;
5559
5660 return [ {
5761 type : "html" ,
@@ -64,15 +68,15 @@ const MarkdownReader = {
6468 return [ {
6569 type : "html" ,
6670 regex : / < a h r e f = " # ( .* ) " > / g,
67- replace : "<a href='# /" + this . document + "/ $1'>"
71+ replace : "<a href='/" + ( this . document ? this . document + "#" : "" ) + " $1'>"
6872 } ] ;
6973 } ) ;
7074
7175 showdown . extension ( 'other-page-links-replacer' , ( ) => {
7276 return [ {
7377 type : "html" ,
7478 regex : / < a h r e f = " \. ? \/ ? ( d o c s \/ ) ? ( .* ?) \. m d \# ? ( .* ?) " > / g,
75- replace : "<a href='# /$2/ $3'>"
79+ replace : "<a href='/$2# $3'>"
7680 } ] ;
7781 } ) ;
7882
0 commit comments