File tree Expand file tree Collapse file tree 1 file changed +19
-1
lines changed
Expand file tree Collapse file tree 1 file changed +19
-1
lines changed Original file line number Diff line number Diff line change @@ -46,7 +46,10 @@ document.addEventListener('click', (e) => {
4646 const el = ( e . target as HTMLElement ) ?. closest ( 'a' ) ;
4747 if ( el ) {
4848 const href = el . getAttribute ( 'href' ) ;
49- if ( ! href . includes ( '://' ) ) {
49+ if ( href . startsWith ( '#' ) ) {
50+ const node = findHeading ( href . slice ( 1 ) ) ;
51+ if ( node ) highlightNode ( node ) ;
52+ } else if ( ! href . includes ( '://' ) ) {
5053 vscode . postMessage ( {
5154 type : 'openFile' ,
5255 data : href ,
@@ -98,6 +101,21 @@ function clickHandler(type: string) {
98101 } ;
99102}
100103
104+ function findHeading ( id : string ) {
105+ function dfs ( node : INode ) {
106+ if ( ! / ^ h \d $ / . test ( node . payload . tag as string ) ) return false ;
107+ const normalizedId = node . content . trim ( ) . replace ( / \W / g, '-' ) . toLowerCase ( ) ;
108+ if ( normalizedId === id ) {
109+ target = node ;
110+ return true ;
111+ }
112+ return node . children ?. some ( dfs ) ;
113+ }
114+ let target : INode | undefined ;
115+ dfs ( root ) ;
116+ return target ;
117+ }
118+
101119function findActiveNode ( line : number ) {
102120 function dfs ( node : INode ) {
103121 const [ start , end ] =
You can’t perform that action at this time.
0 commit comments