@@ -23,6 +23,7 @@ const md = new Remarkable({
23
23
export interface MarkdownHeading {
24
24
title ?: string ;
25
25
id : string ;
26
+ slug ?: string ;
26
27
content ?: string ;
27
28
children ?: StringMap < MarkdownHeading > ;
28
29
}
@@ -52,12 +53,14 @@ export class MdRenderer {
52
53
}
53
54
54
55
saveHeading ( title : string , parent :MarkdownHeading = { id :null , children : this . headings } ) :MarkdownHeading {
55
- let id = slugify ( title ) ;
56
+ let slug = slugify ( title ) ;
57
+ let id = slug ;
56
58
if ( parent && parent . id ) id = `${ parent . id } /${ id } ` ;
57
59
parent . children = parent . children || { } ;
58
60
parent . children [ id ] = {
59
61
title,
60
- id
62
+ id,
63
+ slug
61
64
} ;
62
65
return parent . children [ id ] ;
63
66
}
@@ -110,12 +113,14 @@ export class MdRenderer {
110
113
this . currentTopHeading = this . saveHeading ( content ) ; ;
111
114
let id = this . currentTopHeading . id ;
112
115
return `<h${ tokens [ idx ] . hLevel } section="section/${ id } ">` +
113
- `<a class="share-link" href="#section/${ id } "></a>` ;
116
+ `<a class="share-link" href="#section/${ id } "></a>` +
117
+ `<a name="${ id . toLowerCase ( ) } "></a>` ;
114
118
} else if ( tokens [ idx ] . hLevel === 2 ) {
115
119
let heading = this . saveHeading ( content , this . currentTopHeading ) ;
116
120
let contentSlug = `${ heading . id } ` ;
117
121
return `<h${ tokens [ idx ] . hLevel } section="section/${ heading . id } ">` +
118
- `<a class="share-link" href="#section/${ contentSlug } "></a>` ;
122
+ `<a class="share-link" href="#section/${ contentSlug } "></a>` +
123
+ `<a name="${ heading . slug . toLowerCase ( ) } "></a>` ;
119
124
}
120
125
}
121
126
}
0 commit comments