From 3fdd194cc68800b8701236688dc3e397cd68fee1 Mon Sep 17 00:00:00 2001 From: Alexandre Rademaker Date: Tue, 17 Nov 2026 15:39:53 -0300 Subject: [PATCH 1/4] chore: upgrade to Verso v4.36.0 and Lean v4.36.0 - Pin Verso to the v4.36.0 tag instead of tracking main - Bump lean-toolchain to leanprover/lean4:v4.36.0 - Update transitive dependencies to the revisions used by Verso v4.36.0 - Port to Lean.Html (now in Lean core): `.tag` -> `.element`, `.text true` -> `.text`, `.text false` -> `.raw`, and handle `.raw` in pattern matches - Reuse Verso's `Html.setAttribute` in Components.Basic This change was prepared with the assistance of an AI tool (Claude Code) and reviewed by the author. --- Lang/Components/ArchiveEntry.lean | 10 +++++----- Lang/Components/Basic.lean | 7 +------ Lang/Components/LearnCard.lean | 2 +- Lang/Components/Title.lean | 4 ++-- Lang/Features.lean | 8 ++++---- Lang/Theme/Blog.lean | 27 ++++++++++++++------------- lake-manifest.json | 12 ++++++------ lakefile.lean | 2 +- lean-toolchain | 2 +- 9 files changed, 35 insertions(+), 39 deletions(-) diff --git a/Lang/Components/ArchiveEntry.lean b/Lang/Components/ArchiveEntry.lean index fe20d50..cd9175d 100644 --- a/Lang/Components/ArchiveEntry.lean +++ b/Lang/Components/ArchiveEntry.lean @@ -10,9 +10,9 @@ namespace Components private def extractText (html : Html) : String := match html with - | Html.text _ content => content - | Html.tag _ _ contents => extractText contents - | Html.seq contents => + | .text content | .raw content => content + | .element _ _ contents => extractText contents + | .seq contents => contents.foldl (fun acc h => acc ++ extractText h) "" private def htmlTextLength (html : Html) : Nat := @@ -35,7 +35,7 @@ private def truncateHtml (html : Html) (maxLength : Nat) : Html := else acc ++ "..." else buildResult newAcc rest let truncatedText := buildResult "" words - Html.text false truncatedText + Lean.Html.raw truncatedText def archiveEntry (target : String) (metadata : Option Post.PartMetadata) (title : String) (summary : Option Html) (image : Option (String × String)) : Html := {{ @@ -48,7 +48,7 @@ def archiveEntry (target : String) (metadata : Option Post.PartMetadata) (title | none => Html.empty | some md => {{
- {{(md : Post.PartMetadata).authors.map ({{
{{Html.text true ·}}
}}) |>.toArray}} + {{(md : Post.PartMetadata).authors.map ({{
{{Lean.Html.text ·}}
}}) |>.toArray}}
{{md.date.toIso8601String}}
diff --git a/Lang/Components/Basic.lean b/Lang/Components/Basic.lean index e5ed308..64e2172 100644 --- a/Lang/Components/Basic.lean +++ b/Lang/Components/Basic.lean @@ -40,12 +40,7 @@ partial defmethod Array.chunk (array : Array α) (size : Nat) : Array (Array α) Sets or updates the given attribute on the first HTML tag node. -/ def setAttribute (attr : String) (value : String) (html : Html) : Html := - match html with - | .tag name attrs children => - match attrs.findIdx? ((· == attr) ∘ Prod.fst) with - | none => .tag name (attrs.push (attr, value)) children - | some i => .tag name (attrs.set! i (attr, value)) children - | _ => html + html.setAttribute attr value /-- Sets an attribute on an HTML element only if the value is defined. diff --git a/Lang/Components/LearnCard.lean b/Lang/Components/LearnCard.lean index 1778c03..d1b9a19 100644 --- a/Lang/Components/LearnCard.lean +++ b/Lang/Components/LearnCard.lean @@ -42,7 +42,7 @@ def learnCard (card : Card) : ComponentM Html := do {{ if card.tags.isEmpty then .empty else {{
- {{ card.tags.map fun tag => {{ {{ .text true tag }} }} }} + {{ card.tags.map fun tag => {{ {{ .text tag }} }} }}
}} }} diff --git a/Lang/Components/Title.lean b/Lang/Components/Title.lean index 63734f8..f37ec25 100644 --- a/Lang/Components/Title.lean +++ b/Lang/Components/Title.lean @@ -30,12 +30,12 @@ block_component +directive sectionTitle' (tagg : Option String) (title : String) block_component +directive pageTitle (level : Nat) (title : String) where toHtml _ _ _ _ _ := do - return Html.tag s!"h{level}" #[("class", "page-title")] (.text true title) + return Lean.Html.element s!"h{level}" #[("class", "page-title")] (.text title) block_component +directive header (level : Nat) (title : String) where toHtml _ _ _ _ _ := do - return Html.tag s!"h{level}" #[("id", Verso.Genre.Blog.slugifyTitle title)] (.text true title) + return Lean.Html.element s!"h{level}" #[("id", Verso.Genre.Blog.slugifyTitle title)] (.text title) end Components end Lang diff --git a/Lang/Features.lean b/Lang/Features.lean index dced9d2..1a0f5a4 100644 --- a/Lang/Features.lean +++ b/Lang/Features.lean @@ -110,7 +110,7 @@ partial def toml : CodeBlockExpander where infoHtml : SourceInfo → Html → Html | .original leading _ trailing _, html => - .text false leading.toString ++ html ++ .text false trailing.toString + .raw leading.toString ++ html ++ .raw trailing.toString | _, html => html hl (cls : String) (html : Html) : Html := {{{{html}}}} @@ -150,7 +150,7 @@ where | .node info ``Lake.Toml.decInt elts => infoHtml info <| hl "num" <| elts.map highlightToml | .node info ``Lake.Toml.array elts => infoHtml info <| elts.map highlightToml | .node info ``Lake.Toml.inlineTable elts => infoHtml info <| elts.map highlightToml - | .atom info str => infoHtml info (.text true str) + | .atom info str => infoHtml info (.text str) | other => {{ "Failed to highlight TOML (probably highlightToml in Lang.Features needs another pattern case): " {{toString other}} }} @@ -162,14 +162,14 @@ def collapsedDetails : DirectiveExpander | args, contents => do let summary ← ArgParse.run (.positional `summary .string) args let blocks ← contents.mapM elabBlock - let summary ← ``(Block.other (BlockExt.blob (Html.tag "summary" #[] #[Html.text true $(quote summary)])) #[]) + let summary ← ``(Block.other (BlockExt.blob (Lean.Html.element "summary" #[] #[Lean.Html.text $(quote summary)])) #[]) pure #[← ``(Block.other (BlockExt.htmlWrapper "details" #[]) #[$summary, $blocks,*])] @[directive_expander TODO] def TODO : DirectiveExpander | _, contents => do let blocks ← contents.mapM elabBlock - let header ← ``(Block.other (BlockExt.blob (Html.tag "h3" #[] #[Html.text true "TODO"])) #[]) + let header ← ``(Block.other (BlockExt.blob (Lean.Html.element "h3" #[] #[Lean.Html.text "TODO"])) #[]) pure #[← ``(Block.other (BlockExt.htmlWrapper "div" #[("class", "TODO")]) #[$header, $blocks,*])] @[role_expander TODO] diff --git a/Lang/Theme/Blog.lean b/Lang/Theme/Blog.lean index 4c07e9b..c715af2 100644 --- a/Lang/Theme/Blog.lean +++ b/Lang/Theme/Blog.lean @@ -23,23 +23,24 @@ def archiveEntry : Template := do return #[Components.archiveEntry target post.contents.metadata post.contents.titleString summary none] partial def removeWrapper : Html → String - | .text _ s => s - | .tag _ _ h => removeWrapper h + | .text s | .raw s => s + | .element _ _ h => removeWrapper h | .seq hs => String.intercalate " " (hs.toList.map removeWrapper) partial def addSlug : Html → Html - | .text s e => .text s e - | .tag t a h => + | .text s => .text s + | .raw s => .raw s + | .element t a h => match t with - | "h1" | "h2" | "h3" | "h4" => .tag t (a.push ("id", createSlug (removeWrapper h))) h - | _ => .tag t a (addSlug h) + | "h1" | "h2" | "h3" | "h4" => .element t (a.push ("id", createSlug (removeWrapper h))) h + | _ => .element t a (addSlug h) | .seq h => .seq (h.map addSlug) partial def collectH1 (html : Html) (linkPrefix : String := "") : Option Html := let res := (collect [] html |>.reverse) if ¬ res.isEmpty then let (html, _) := compact 2 res - Html.tag "ol" #[] #[Html.seq (html.toArray |>.map (Html.tag "li" #[]))] + Lean.Html.element "ol" #[] #[Html.seq (html.toArray |>.map (Lean.Html.element "li" #[]))] else none where @@ -51,8 +52,8 @@ partial def collectH1 (html : Html) (linkPrefix : String := "") : Option Html := | _ => 0 collect (col : List (Nat × String)) : Html → List (Nat × String) - | .text _ _ => col - | .tag t _ h => + | .text _ | .raw _ => col + | .element t _ h => match t with | "h1" | "h2" | "h3" | "h4" => (getLevel t, removeWrapper h) :: col | _ => collect col h @@ -62,10 +63,10 @@ partial def collectH1 (html : Html) (linkPrefix : String := "") : Option Html := | (level, str) :: xs => if level = current then let slug := createSlug str - let headingLink := Html.tag "a" #[("href", s!"{linkPrefix}#{slug}")] #[Html.text false str] + let headingLink := Lean.Html.element "a" #[("href", s!"{linkPrefix}#{slug}")] #[Lean.Html.raw str] let (children, remaining) := compactChildren (level + 1) xs - let item := if children.isEmpty then headingLink else Html.seq #[headingLink, Html.tag "ol" #[] (Html.seq children.toArray)] + let item := if children.isEmpty then headingLink else Html.seq #[headingLink, Lean.Html.element "ol" #[] (Html.seq children.toArray)] let (siblings, final) := compact level remaining (item :: siblings, final) @@ -80,7 +81,7 @@ partial def collectH1 (html : Html) (linkPrefix : String := "") : Option Html := if level >= minLevel then let (item, remaining) := compact level ((level, str) :: xs) let (siblings, final) := compactChildren minLevel remaining - (item.map (Html.tag "li" #[]) ++ siblings, final) + (item.map (Lean.Html.element "li" #[]) ++ siblings, final) else ([], (level, str) :: xs) | [] => ([], []) @@ -99,7 +100,7 @@ def postTemplate : Template := do | none => Html.empty | some md => {{