File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11window . MathJax = {
22 tex : {
3- packages : { '[+]' : [ 'noerrors' , 'ams' ] } ,
3+ packages : { '[+]' : [ 'noerrors' , 'ams' , 'tipa' ] } ,
44 macros : {
55 qed : "\\square" ,
66 ran : "\\text{ran}" ,
Original file line number Diff line number Diff line change @@ -40,10 +40,10 @@ marked.setOptions({
4040const headingData = [ ] ;
4141const renderer = new marked . Renderer ( ) ;
4242
43- renderer . heading = ( text , level ) => {
44- const source = text ;
43+ renderer . heading = ( text , level , raw ) => {
44+ const source = typeof raw === 'string' ? raw : text ;
4545 const slug = slugify ( source ) ;
46- headingData . push ( { text : source , level, slug } ) ;
46+ headingData . push ( { text, level, slug } ) ;
4747 return `<h${ level } id="${ slug } ">${ text } </h${ level } >` ;
4848} ;
4949
@@ -79,11 +79,19 @@ fetch(`/notes/courses/${course}/${noteSlug}.md`)
7979 headingData . forEach ( ( { text, level, slug } ) => {
8080 const li = document . createElement ( "li" ) ;
8181 li . style . marginLeft = `${ ( level - 1 ) * 16 } px` ;
82- li . innerHTML = `<a href="#${ slug } ">${ text } </a>` ;
82+
83+ const a = document . createElement ( "a" ) ;
84+ a . href = `#${ slug } ` ;
85+ a . textContent = text ;
86+ li . append ( a ) ;
87+ li . addEventListener ( "click" , ( e ) => {
88+ e . preventDefault ( ) ;
89+ document . getElementById ( slug ) . scrollIntoView ( { behavior : "smooth" } ) ;
90+ } ) ;
8391 ul . append ( li ) ;
8492 } ) ;
8593
86- tocNav . append ( ul ) ;
94+ tocNav . appendChild ( ul ) ;
8795 container . prepend ( tocNav ) ;
8896 }
8997
You can’t perform that action at this time.
0 commit comments