File tree Expand file tree Collapse file tree 4 files changed +30
-8
lines changed Expand file tree Collapse file tree 4 files changed +30
-8
lines changed Original file line number Diff line number Diff line change @@ -105,3 +105,13 @@ let getVersionString = url =>
105105let normalizePath = string => {
106106 string -> String .replaceRegExp (/ \/ $/ , "" )-> String .toLocaleLowerCase
107107}
108+
109+ let normalizeAnchor = string => {
110+ string
111+ -> String .replaceRegExp (/ <[^ >]+ >/ g , "" )
112+ -> String .replaceRegExp (/ ([\r \n ]+ + )+/ g , "" )
113+ -> String .replaceAll (" " , "-" )
114+ -> String .replaceAll ("_" , "-" )
115+ -> String .replaceAllRegExp (/ [^ a - zA - Z0 - 9 - ]/ g , "" )
116+ -> String .toLocaleLowerCase
117+ }
Original file line number Diff line number Diff line change @@ -32,3 +32,5 @@ let getVersionFromStorage: storageKey => option<string>
3232let getVersionString : t => string
3333
3434let normalizePath : string => string
35+
36+ let normalizeAnchor : string => string
Original file line number Diff line number Diff line change 11// This file was automatically converted to ReScript from 'Markdown.re'
22// Check the output and make sure to delete the original file
33
4- external childrenToString : React .element => string = "%identity"
4+ // type el = {@as("type") _type?: string}
5+
6+ // external elementObject: React.element => el = "%identity"
7+
8+ let childrenToString = element => {
9+ JSON .stringifyAny (ReactDOMServer .renderToStaticMarkup (element ))
10+ -> Option .getOr ("" )
11+ -> String .replaceRegExp (/ <[^ >]+ >/ g , "" )
12+ -> String .replaceRegExp (/ ([\r \n ]+ + )+/ g , "" )
13+ }
514
615module P = {
716 @react.component
@@ -143,10 +152,7 @@ module H2 = {
143152 // TODO: RR7 - this can be improved, but I need to figure out what the other possible types are
144153 let title = {
145154 try {
146- childrenToString (children )
147- -> String .toLowerCase
148- -> String .replaceAll (" " , "-" )
149- -> String .replaceAll ("." , "" )
155+ childrenToString (children )-> Url .normalizeAnchor
150156 } catch {
151157 | _ => ""
152158 }
Original file line number Diff line number Diff line change @@ -24,14 +24,18 @@ module Toc = {
2424 let make = (~entries : array <TableOfContents .entry >) =>
2525 <ul className = "mt-3 py-1 mb-4 border-l border-fire-10" >
2626 {Array .map (entries , ({header , href }) => {
27- <li key = header className = "pl-2 mt-2 first:mt-1" >
27+ <li key = header className = "pl-2 mt-2 first:mt-1" dataTestId = header >
2828 <Link .String
2929 onClick = {_evt => scrollToAnchor (href )}
30- to = href
30+ to = { "#" ++ href -> Url . normalizeAnchor }
3131 className = "font-normal block text-14 text-gray-40 leading-tight hover:text-gray-80"
3232 preventScrollReset = true
3333 >
34- {React .string (header )}
34+ {React .string (
35+ header
36+ -> String .replaceRegExp (/ <[^ >]+ >/ g , "" )
37+ -> String .replaceRegExp (/ ([\r \n ]+ + )+/ g , "" ),
38+ )}
3539 </Link .String >
3640 </li >
3741 })-> React .array }
You can’t perform that action at this time.
0 commit comments