File tree Expand file tree Collapse file tree 2 files changed +17
-4
lines changed Expand file tree Collapse file tree 2 files changed +17
-4
lines changed Original file line number Diff line number Diff line change @@ -339,4 +339,17 @@ function debounce(fn, delay = 50) {
339
339
}
340
340
}
341
341
342
- if ( window . page && / ^ c h a p t e r | h i n t s $ / . test ( window . page . type ) ) chapterInteraction ( )
342
+ if ( window . page && / ^ c h a p t e r | h i n t s $ / . test ( window . page . type ) ) {
343
+ chapterInteraction ( )
344
+ // 3rd-edition-style anchor
345
+ let { hash} = document . location
346
+ if ( / ^ # [ p h i c ] _ ./ . test ( hash ) ) {
347
+ let exists = document . getElementById ( hash . replace ( / _ / , "-" ) )
348
+ if ( exists ) {
349
+ document . location . hash = hash . replace ( / _ / , "-" )
350
+ } else {
351
+ let chapter = / \/ [ ^ \/ ] + \. h t m l / . exec ( document . location )
352
+ if ( chapter ) document . location = `https://eloquentjavascript.net/3rd_edition${ chapter [ 0 ] } ${ hash } `
353
+ }
354
+ }
355
+ }
Original file line number Diff line number Diff line change @@ -112,11 +112,11 @@ export function transformTokens(tokens, options) {
112
112
i += 2
113
113
} else {
114
114
if ( type == "paragraph_open" )
115
- tok . hashID = "p_ " + hash ( startAndEnd ( childrenText ( tokens [ i + 1 ] ) ) )
115
+ tok . hashID = "p- " + hash ( startAndEnd ( childrenText ( tokens [ i + 1 ] ) ) )
116
116
else if ( type == "heading_open" )
117
- tok . hashID = ( tok . tag == "h2" ? "h_ " : "i_ " ) + hash ( childrenText ( tokens [ i + 1 ] ) )
117
+ tok . hashID = ( tok . tag == "h2" ? "h- " : "i- " ) + hash ( childrenText ( tokens [ i + 1 ] ) )
118
118
else if ( type == "fence" )
119
- tok . hashID = "c_ " + hash ( tok . content )
119
+ tok . hashID = "c- " + hash ( tok . content )
120
120
121
121
if ( tok . children ) tok . children = transformInline ( tok . children , options , tokens [ i - 1 ] . type )
122
122
You can’t perform that action at this time.
0 commit comments