@@ -70,7 +70,7 @@ partial def xmlGetHeadingId (el : Xml.Element) : String :=
7070def nameToLink? (s : String) : HtmlM (Option String) := do
7171 let res ← getResult
7272 if s.endsWith ".lean" && s.contains '/' then
73- return (← getRoot) ++ s.dropRight 5 ++ ".html"
73+ return (← getRoot) ++ s.dropEnd 5 ++ ".html"
7474 else if let some name := Lean.Syntax.decodeNameLit ("`" ++ s) then
7575 -- with exactly the same name
7676 if res.name2ModIdx.contains name then
@@ -106,7 +106,7 @@ def nameToLink? (s : String) : HtmlM (Option String) := do
106106def extendLink (s : String) : HtmlM String := do
107107 -- for intra doc links
108108 if s.startsWith "##" then
109- if let some link ← nameToLink? (s.drop 2 ) then
109+ if let some link ← nameToLink? (s.drop 2 ).copy then
110110 return link
111111 else
112112 return s! "{ ← getRoot} find/?pattern={ s.drop 2 } #doc"
@@ -158,7 +158,7 @@ def addHeadingAttributes (el : Element) (funName : String)
158158/-- Find a bibitem if `href` starts with `thePrefix`. -/
159159def findBibitem? (href : String) (thePrefix : String := "" ) : HtmlM (Option BibItem) := do
160160 if href.startsWith thePrefix then
161- pure <| (← read).refsMap[href.drop thePrefix.length]?
161+ pure <| (← read).refsMap[href.drop thePrefix.length |>.copy ]?
162162 else
163163 pure .none
164164
@@ -206,8 +206,8 @@ def autoLink (el : Element) : HtmlM Element := do
206206 let attributes := Std.TreeMap.empty.insert "href" link
207207 return [Content.Element <| Element.Element "a" attributes #[Content.Character s]]
208208 | none =>
209- let sHead := s.dropRightWhile (· != '.' )
210- let sTail := s.takeRightWhile (· != '.' )
209+ let sHead := s.dropEndWhile (· != '.' ) |>.copy
210+ let sTail := s.takeEndWhile (· != '.' ) |>.copy
211211 let link'? ← nameToLink? sTail
212212 match link'? with
213213 | some link' =>
@@ -242,13 +242,13 @@ partial def modifyElement (element : Element) (funName : String) : HtmlM Element
242242 return ⟨ name, attrs, ← modifyContents contents funName modifyElement ⟩
243243
244244/-- Find all references in a markdown text. -/
245- partial def findAllReferences (refsMap : Std.HashMap String BibItem) (s : String) (i : String .Pos.Raw := 0 )
245+ partial def findAllReferences (refsMap : Std.HashMap String BibItem) (s : String) (i : s .Pos := s.startPos )
246246 (ret : Std.HashSet String := ∅) : Std.HashSet String :=
247- let lps := s.posOfAux '[' s.rawEndPos i
248- if lps < s.rawEndPos then
249- let lpe := s.posOfAux ']' s.rawEndPos lps
250- if lpe < s.rawEndPos then
251- let citekey := Substring.Raw.toString ⟨s, ⟨ lps.1 + 1 ⟩, lpe⟩
247+ let lps := i.find '['
248+ if hs : lps ≠ s.endPos then
249+ let lpe := lps.find ']'
250+ if lpe ≠ s.endPos then
251+ let citekey := s.extract ( lps.next hs) lpe
252252 match refsMap[citekey]? with
253253 | .some _ => findAllReferences refsMap s lpe (ret.insert citekey)
254254 | .none => findAllReferences refsMap s lpe ret
@@ -264,7 +264,7 @@ def docStringToHtml (docString : String) (funName : String) : HtmlM (Array Html)
264264 s! "[{ s} ]: references.html#ref_{ s} \n " )
265265 match MD4Lean.renderHtml (docString ++ refsMarkdown) with
266266 | .some rendered =>
267- match manyDocument ⟨rendered, rendered.startValidPos ⟩ with
267+ match manyDocument ⟨rendered, rendered.startPos ⟩ with
268268 | .success _ res =>
269269 let newRes ← modifyElements res funName modifyElement
270270 -- TODO: use `toString` instead of `eToStringEscaped`
0 commit comments