File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 55 < link rel ="icon " type ="image/x-icon " href ="favicon.svg " />
66 < link rel ="stylesheet " href ="result.css " />
77 < script src ="https://cdn.jsdelivr.net/npm/marked/marked.min.js "> </ script >
8+ < script src ="https://cdn.jsdelivr.net/npm/dompurify@3.2.6/dist/purify.min.js "> </ script >
89 </ head >
910 < body >
1011 < div id ="markdown-container "> </ div >
2122 ) ;
2223 }
2324 const markdownText = await response . text ( ) ;
24- markdownContainer . innerHTML = marked . parse ( markdownText ) ;
25+ const renderedMarkdown = marked . parse ( markdownText ) ;
26+ markdownContainer . innerHTML = DOMPurify . sanitize ( renderedMarkdown ) ;
2527 addHeadingAnchors ( ) ;
2628 } catch ( error ) {
2729 console . error ( "Error loading markdown:" , error ) ;
3739 . replaceAll ( " " , "-" )
3840 . replaceAll ( "&" , "" )
3941 . replaceAll ( "/" , "" ) ;
42+
4043 const anchor = document . createElement ( "a" ) ;
4144 anchor . id = anchorId ;
4245 anchor . href = "#" + anchorId ;
4851 const hash = window . location . hash ;
4952 if ( hash ) {
5053 const decodedHash = decodeURIComponent ( hash ) ;
51- const target = document . querySelector ( decodedHash ) ;
54+ const targetId = decodedHash . startsWith ( "#" )
55+ ? decodedHash . slice ( 1 )
56+ : decodedHash ;
57+ const target = document . getElementById ( targetId ) ;
58+
5259 if ( target ) {
5360 target . scrollIntoView ( ) ;
5461 }
You can’t perform that action at this time.
0 commit comments