diff --git a/doc-gen4/DocGen4/Output.lean b/doc-gen4/DocGen4/Output.lean index 874aed388..04e6ccc0b 100644 --- a/doc-gen4/DocGen4/Output.lean +++ b/doc-gen4/DocGen4/Output.lean @@ -49,13 +49,13 @@ def htmlOutputSetup (config : SiteBaseContext) (tacticInfo : Array (Process.Tact FS.createDirAll <| declarationsBasePath config.buildDir -- All the doc-gen static stuff - let indexHtml := ReaderT.run index config |>.toString - let notFoundHtml := ReaderT.run notFound config |>.toString - let foundationalTypesHtml := ReaderT.run foundationalTypes config |>.toString - let navbarHtml := ReaderT.run navbar config |>.toString - let searchHtml := ReaderT.run search config |>.toString - let referencesHtml := ReaderT.run (references (← collectBackrefs config.buildDir)) config |>.toString - let tacticsHtml := ReaderT.run (tactics tacticInfo) config |>.toString + let indexHtml := ReaderT.run index config |>.render + let notFoundHtml := ReaderT.run notFound config |>.render + let foundationalTypesHtml := ReaderT.run foundationalTypes config |>.render + let navbarHtml := ReaderT.run navbar config |>.render + let searchHtml := ReaderT.run search config |>.render + let referencesHtml := ReaderT.run (references (← collectBackrefs config.buildDir)) config |>.render + let tacticsHtml := ReaderT.run (tactics tacticInfo) config |>.render let docGenStatic := #[ ("style.css", styleCss), ("favicon.svg", faviconSvg), @@ -80,7 +80,7 @@ def htmlOutputSetup (config : SiteBaseContext) (tacticInfo : Array (Process.Tact for (fileName, content) in docGenStatic do writeFileAtomic (basePath config.buildDir / fileName) content - let findHtml := ReaderT.run find { config with depthToRoot := 1 } |>.toString + let findHtml := ReaderT.run find { config with depthToRoot := 1 } |>.render let findStatic := #[ ("index.html", findHtml), ("find.js", findJs) @@ -147,7 +147,7 @@ def htmlOutputResultsParallel (baseConfig : SiteBaseContext) (dbPath : System.Fi let filePath := baseConfig.buildDir / relFilePath if let .some d := filePath.parent then FS.createDirAll d - writeFileAtomic filePath moduleHtml.toString + writeFileAtomic filePath moduleHtml.render -- Write backrefs JSON writeFileAtomic (declarationsBasePath baseConfig.buildDir / s!"backrefs-{module.name}.json") @@ -335,7 +335,7 @@ def updateNavbarFromDisk (buildDir : System.FilePath) : IO Unit := do refs := refs } -- Regenerate navbar - let navbarHtml := ReaderT.run navbar baseConfig |>.toString + let navbarHtml := ReaderT.run navbar baseConfig |>.render writeFileAtomic (docDir / "navbar.html") navbarHtml end DocGen4 diff --git a/doc-gen4/DocGen4/Output/Arg.lean b/doc-gen4/DocGen4/Output/Arg.lean index 536f7268c..1a4085114 100644 --- a/doc-gen4/DocGen4/Output/Arg.lean +++ b/doc-gen4/DocGen4/Output/Arg.lean @@ -12,7 +12,7 @@ type of binder it has. def argToHtml (arg : Process.Arg) : HtmlM Html := do let node ← renderedCodeToHtml arg.binder let inner := [node] - let html := Html.element "span" false #[("class", "decl_args")] #[inner] + let html := .element "span" #[("class", "decl_args")] #[inner] if arg.implicit then return {html} else diff --git a/doc-gen4/DocGen4/Output/DocString.lean b/doc-gen4/DocGen4/Output/DocString.lean index fbb491c68..35a23d3a8 100644 --- a/doc-gen4/DocGen4/Output/DocString.lean +++ b/doc-gen4/DocGen4/Output/DocString.lean @@ -179,7 +179,7 @@ def autoLinkInline (ss : Array String) : HtmlM (Array Html) := do for part in parts do match ← nameToLink? part with | some link => - result := result.push <| Html.element "a" true #[("href", link)] #[Html.text part] + result := result.push <| .element "a" #[("href", link)] #[Html.text part] | none => let sHead := part.dropEndWhile (· != '.') |>.copy let sTail := part.takeEndWhile (· != '.') |>.copy @@ -187,7 +187,7 @@ def autoLinkInline (ss : Array String) : HtmlM (Array Html) := do | some link => if !sHead.isEmpty then result := result.push <| Html.text sHead - result := result.push <| Html.element "a" true #[("href", link)] #[Html.text sTail] + result := result.push <| .element "a" #[("href", link)] #[Html.text sTail] | none => result := result.push <| Html.text part return result @@ -211,16 +211,16 @@ partial def renderText (t : MD4Lean.Text) (funName : String) (inLink : Bool := f | .entity s => return #[Html.raw s] | .em ts => let inner ← renderTexts ts funName inLink - return #[Html.element "em" true #[] inner] + return #[.element "em" #[] inner] | .strong ts => let inner ← renderTexts ts funName inLink - return #[Html.element "strong" true #[] inner] + return #[.element "strong" #[] inner] | .u ts => let inner ← renderTexts ts funName inLink - return #[Html.element "u" true #[] inner] + return #[.element "u" #[] inner] | .del ts => let inner ← renderTexts ts funName inLink - return #[Html.element "del" true #[] inner] + return #[.element "del" #[] inner] | .a href title _isAuto children => let hrefStr := attrTextToString href let titleStr := attrTextToString title @@ -240,13 +240,13 @@ partial def renderText (t : MD4Lean.Text) (funName : String) (inLink : Bool := f let mut attrs : Array (String × String) := #[("href", extHref)] attrs := attrs.push ("title", bibitem.plaintext) attrs := attrs.push ("id", s!"_backref_{newBackref.index}") - return #[Html.element "a" true attrs newChildren] + return #[.element "a" attrs newChildren] | .none => let childrenHtml ← renderTexts children funName (inLink := true) let mut attrs : Array (String × String) := #[("href", extHref)] if !titleStr.isEmpty then attrs := attrs.push ("title", titleStr) - return #[Html.element "a" true attrs childrenHtml] + return #[.element "a" attrs childrenHtml] | .img src title alt => let srcStr := Html.escape (attrTextToString src) let titleStr := Html.escape (attrTextToString title) @@ -262,7 +262,7 @@ partial def renderText (t : MD4Lean.Text) (funName : String) (inLink : Bool := f pure #[Html.text (String.join ss.toList)] else autoLinkInline ss - return #[Html.element "code" true #[] inner] + return #[.element "code" #[] inner] -- Math is rendered with dollar signs because MathJax will later render them | .latexMath ss => let content := String.join ss.toList @@ -274,7 +274,7 @@ partial def renderText (t : MD4Lean.Text) (funName : String) (inLink : Bool := f | .wikiLink target children => let inner ← renderTexts children funName inLink let targetStr := attrTextToString target - return #[Html.element "x-wikilink" true #[("data-target", targetStr)] inner] + return #[.element "x-wikilink" #[("data-target", targetStr)] inner] /-- Render an array of `MD4Lean.Text` inline elements to HTML. -/ partial def renderTexts (texts : Array MD4Lean.Text) (funName : String) (inLink : Bool := false) : HtmlM (Array Html) := do @@ -291,13 +291,13 @@ partial def renderBlock (block : MD4Lean.Block) (funName : String) (tight : Bool if tight then return inner else - return #[Html.element "p" true #[] inner] + return #[.element "p" #[] inner] | .ul isTight _mark items => let mut lis : Array Html := #[] for item in items do let liHtml ← renderLi item funName isTight lis := lis ++ liHtml - return #[Html.element "ul" true #[] lis] + return #[.element "ul" #[] lis] | .ol isTight start _mark items => let mut lis : Array Html := #[] for item in items do @@ -305,15 +305,15 @@ partial def renderBlock (block : MD4Lean.Block) (funName : String) (tight : Bool lis := lis ++ liHtml let attrs : Array (String × String) := if start != 1 then #[("start", toString start)] else #[] - return #[Html.element "ol" true attrs lis] + return #[.element "ol" attrs lis] | .hr => return #[Html.raw "
\n"] | .header level texts => let id := mdGetHeadingId texts let inner ← renderTexts texts funName - let anchor := Html.element "a" true #[("class", "hover-link"), ("href", s!"#{id}")] #[Html.text "#"] + let anchor := .element "a" #[("class", "hover-link"), ("href", s!"#{id}")] #[Html.text "#"] let children := inner.push (Html.text " ") |>.push anchor let tag := s!"h{level}" - return #[Html.element tag true #[("id", id), ("class", "markdown-heading")] children] + return #[.element tag #[("id", id), ("class", "markdown-heading")] children] | .code _info lang _fenceChar content => let langStr := attrTextToString lang let codeAttrs : Array (String × String) := @@ -323,31 +323,31 @@ partial def renderBlock (block : MD4Lean.Block) (funName : String) (tight : Bool autoLinkInline content else pure #[Html.text (String.join content.toList)] - let codeElem := Html.element "code" true codeAttrs inner - return #[Html.element "pre" true #[] #[codeElem]] + let codeElem : Html := .element "code" codeAttrs inner + return #[.element "pre" #[] #[codeElem]] | .html content => return #[Html.raw (String.join content.toList)] | .blockquote blocks => let mut inner : Array Html := #[] for b in blocks do inner := inner ++ (← renderBlock b funName) - return #[Html.element "blockquote" true #[] inner] + return #[.element "blockquote" #[] inner] | .table head body => let mut headCells : Array Html := #[] for cell in head do let cellHtml ← renderTexts cell funName - headCells := headCells.push (Html.element "th" true #[] cellHtml) - let headRow := Html.element "tr" true #[] headCells - let thead := Html.element "thead" true #[] #[headRow] + headCells := headCells.push (.element "th" #[] cellHtml) + let headRow : Html := .element "tr" #[] headCells + let thead := .element "thead" #[] #[headRow] let mut bodyRows : Array Html := #[] for row in body do let mut rowCells : Array Html := #[] for cell in row do let cellHtml ← renderTexts cell funName - rowCells := rowCells.push (Html.element "td" true #[] cellHtml) - bodyRows := bodyRows.push (Html.element "tr" true #[] rowCells) - let tbody := Html.element "tbody" true #[] bodyRows - return #[Html.element "table" true #[] #[thead, tbody]] + rowCells := rowCells.push (.element "td" #[] cellHtml) + bodyRows := bodyRows.push (.element "tr" #[] rowCells) + let tbody : Html := .element "tbody" #[] bodyRows + return #[.element "table" #[] #[thead, tbody]] /-- Render a list item to HTML. -/ partial def renderLi (li : MD4Lean.Li MD4Lean.Block) (funName : String) (tight : Bool) : HtmlM (Array Html) := do @@ -360,7 +360,7 @@ partial def renderLi (li : MD4Lean.Li MD4Lean.Block) (funName : String) (tight : inner := inner.push (Html.raw "") for b in li.contents do inner := inner ++ (← renderBlock b funName tight) - return #[Html.element "li" true #[] inner] + return #[.element "li" #[] inner] end diff --git a/doc-gen4/DocGen4/Output/Module.lean b/doc-gen4/DocGen4/Output/Module.lean index 02ebc6cde..580089b3b 100644 --- a/doc-gen4/DocGen4/Output/Module.lean +++ b/doc-gen4/DocGen4/Output/Module.lean @@ -43,7 +43,7 @@ and name. -/ def docInfoHeader (doc : DocInfo) : HtmlM Html := do let mut nodes := #[] - nodes := nodes.push <| Html.element "span" false #[("class", "decl_kind")] #[doc.getKindDescription] + nodes := nodes.push <| .element "span" #[("class", "decl_kind")] #[Html.text doc.getKindDescription] -- TODO: Can we inline if-then-else and avoid repeating here? if doc.getSorried then nodes := nodes.push {← declNameToHtmlBreakWithinLink doc.getName} @@ -57,7 +57,7 @@ def docInfoHeader (doc : DocInfo) : HtmlM Html := do | DocInfo.classInfo i => nodes := nodes.append (← structureInfoHeader i) | _ => nodes := nodes - nodes := nodes.push <| Html.element "span" true #[("class", "decl_args")] #[" :"] + nodes := nodes.push <| .element "span" #[("class", "decl_args")] #[Html.text " :"] nodes := nodes.push
[← renderedCodeToHtml doc.getType]
return
[nodes]
@@ -89,7 +89,7 @@ def docInfoToHtml (module : Name) (doc : DocInfo) : HtmlM Html := do let attrsHtml := if attrs.size > 0 then let attrStr := "@[" ++ String.intercalate ", " doc.getAttrs.toList ++ "]" - #[Html.element "div" false #[("class", "attributes")] #[attrStr]] + #[.element "div" #[("class", "attributes")] #[Html.text attrStr]] else #[] -- custom decoration (e.g., verification badges from external tools) @@ -184,7 +184,7 @@ def moduleToHtml (module : Process.Module) : HtmlM Html := withTheReader SiteBas let memberNames := filterDocInfo relevantMembers.iter |>.map DocInfo.getName |>.toArray templateLiftExtends (baseHtmlGenerator module.name.toString) <| pure #[ ← internalNav memberNames module.name, - Html.element "main" false #[] memberDocs + .element "main" #[] memberDocs ] end Output diff --git a/doc-gen4/DocGen4/Output/Tactics.lean b/doc-gen4/DocGen4/Output/Tactics.lean index 54ad7c910..c4d5cba74 100644 --- a/doc-gen4/DocGen4/Output/Tactics.lean +++ b/doc-gen4/DocGen4/Output/Tactics.lean @@ -61,7 +61,7 @@ def tactics (tacticInfo : Array (TacticInfo Html)) : BaseHtmlM Html := do

return to top

[tacticInfo.map (· |>.navLink)] , - Html.element "main" false #[] ( + .element "main" #[] ( #[

The tactic language is a special-purpose programming language for constructing proofs, indicated using the keyword by.

] ++ sectionsHtml) ] diff --git a/doc-gen4/DocGen4/Output/ToHtmlFormat.lean b/doc-gen4/DocGen4/Output/ToHtmlFormat.lean index b6381931d..abb65e387 100644 --- a/doc-gen4/DocGen4/Output/ToHtmlFormat.lean +++ b/doc-gen4/DocGen4/Output/ToHtmlFormat.lean @@ -6,6 +6,7 @@ Authors: Wojciech Nawrocki, Sebastian Ullrich, Henrik Böving -/ import Lean.Data.Json import Lean.Parser +import Lean.Data.Html /-! This module defines: - a representation of HTML trees @@ -16,19 +17,6 @@ namespace DocGen4 open Lean -inductive Html where - -- TODO(WN): it's nameless for shorter JSON; re-add names when we have deriving strategies for From/ToJson - -- element (tag : String) (flatten : Bool) (attrs : Array HtmlAttribute) (children : Array Html) - | element : String → Bool → Array (String × String) → Array Html → Html - /-- A text node, which will be escaped in the output -/ - | text : String → Html - /-- An arbitrary string containing HTML -/ - | raw : String → Html - deriving Repr, BEq, Inhabited, FromJson, ToJson - -instance : Coe String Html := - ⟨Html.text⟩ - namespace Html @@ -57,25 +45,11 @@ where def attributesToString (attrs : Array (String × String)) :String := attrs.foldl (fun acc (k, v) => acc ++ " " ++ k ++ "=\"" ++ escape v ++ "\"") "" --- TODO: Termination proof -partial def toStringAux : Html → String -| element tag false attrs #[text s] => s!"<{tag}{attributesToString attrs}>{escape s}\n" -| element tag false attrs #[raw s] => s!"<{tag}{attributesToString attrs}>{s}\n" -| element tag false attrs #[child] => s!"<{tag}{attributesToString attrs}>\n{child.toStringAux}\n" -| element tag false attrs children => s!"<{tag}{attributesToString attrs}>\n{children.foldl (· ++ toStringAux ·) ""}\n" -| element tag true attrs children => s!"<{tag}{attributesToString attrs}>{children.foldl (· ++ toStringAux ·) ""}" -| text s => escape s -| raw s => s - -def toString (html : Html) : String := - html.toStringAux.trimAsciiEnd.copy - partial def textLength : Html → Nat -| raw s => s.length -- measures lengths of escape sequences too! -| text s => s.length -| element _ _ _ children => - let lengths := children.map textLength - lengths.foldl Nat.add 0 + | .raw s => s.length -- measures lengths of escape sequences too! + | .text s => s.length + | .element _ _ c => textLength c + | .seq s => s.foldl (· + textLength ·) 0 end Html @@ -149,10 +123,10 @@ macro_rules | `(<$n $attrs* />) => do let kind := quote (toString n.getId) let attrs ← translateAttrs attrs - `(Html.element $kind true $attrs #[]) + `(Html.element $kind $attrs (.seq #[])) | `(<$n $attrs* >$children*) => do let (tag, children) ← htmlHelper n children m - `(Html.element $(quote tag) true $(← translateAttrs attrs) $children) + `(Html.element $(quote tag) $(← translateAttrs attrs) (.seq $children)) end Jsx @@ -161,4 +135,30 @@ as the resulting HTML in editors which support it. -/ class ToHtmlFormat (α : Type u) where formatHtml : α → Html +/-! ## Deprecation aliases -/ +-- TODO: Remove aliases later. + +-- Constants with same name and type are re-exported in the old namespace. +export Lean (Html Html.text Html.raw) + +-- Constants whose name or type changed become deprecated protected abbrevs in the old namespace. +set_option linter.unusedVariables false in +@[deprecated Lean.Html.element +typeChanged (since := "2026-09-02")] +protected abbrev Html.element (tag : String) (flatten : Bool) (attrs : Array (String × String)) (children : Array Html) := + Lean.Html.element tag attrs (.ofCollection children) + +@[deprecated Lean.Html.render (since := "2026-09-02")] +protected abbrev Html.toString (html : Html) : String := + Lean.Html.render html + end DocGen4 + +-- Constants whose name or type changed, and which are commonly used with dot notation, +-- also get a deprecated alias in the new namespace. +namespace Lean.Html + +@[deprecated Lean.Html.render (since := "2026-09-02")] +protected abbrev toString (html : Html) : String := + Lean.Html.render html + +end Lean.Html diff --git a/doc-gen4/DocGen4/Output/ToJson.lean b/doc-gen4/DocGen4/Output/ToJson.lean index c95869d81..94e0fe320 100644 --- a/doc-gen4/DocGen4/Output/ToJson.lean +++ b/doc-gen4/DocGen4/Output/ToJson.lean @@ -124,7 +124,7 @@ def DocInfo.toJson (sourceLinker : Option DeclarationRange → String) (info : P let docLink ← declNameToLink info.getName let sourceLink := sourceLinker info.getDeclarationRange let line := info.getDeclarationRange.pos.line - let header := (← docInfoHeader info).toString + let header := (← docInfoHeader info).render let info := { name, kind, doc, docLink, sourceLink, line } return { info, header } diff --git a/lean-toolchain b/lean-toolchain index 1aa2a00d6..2a8f9f07d 100644 --- a/lean-toolchain +++ b/lean-toolchain @@ -1 +1 @@ -leanprover/lean4:nightly-2026-10-01 +leanprover/lean4-pr-releases:pr-release-14935-8eaba5e diff --git a/reference-manual/Main.lean b/reference-manual/Main.lean index 11db40808..89b32eabc 100644 --- a/reference-manual/Main.lean +++ b/reference-manual/Main.lean @@ -14,7 +14,7 @@ open Verso.Genre.Manual.InlineLean open Verso.Output.Html in def plausible := {{ - diff --git a/reference-manual/Manual/Meta/ErrorExplanation.lean b/reference-manual/Manual/Meta/ErrorExplanation.lean index 1e9b16b31..42a53ed95 100644 --- a/reference-manual/Manual/Meta/ErrorExplanation.lean +++ b/reference-manual/Manual/Meta/ErrorExplanation.lean @@ -30,6 +30,6 @@ def getBreakableSuffix (name : Name) : Option String := do htmlText breakableHtml where htmlText : Verso.Output.Html → String - | .text _ txt => txt + | .text txt | .raw txt => txt | .seq elts => elts.foldl (· ++ htmlText ·) "" - | .tag _nm _attrs children => htmlText children + | .element _nm _attrs children => htmlText children diff --git a/reference-manual/Manual/Meta/ErrorExplanation/Header.lean b/reference-manual/Manual/Meta/ErrorExplanation/Header.lean index 30fe4b699..355af37b1 100644 --- a/reference-manual/Manual/Meta/ErrorExplanation/Header.lean +++ b/reference-manual/Manual/Meta/ErrorExplanation/Header.lean @@ -82,8 +82,8 @@ block_extension Block.errorExplanationHeader (metadata : ErrorExplanationExtende ++ (metadata.removedVersion?.map fun v => #[("Removed", v)]).getD #[] let entries := entries.map fun (label, data) => {{ - {{Html.text true label}}": " - {{Html.text true data}} + {{Html.text label}}": " + {{Html.text data}} }} return {{
diff --git a/reference-manual/Manual/Meta/LakeToml/Table.lean b/reference-manual/Manual/Meta/LakeToml/Table.lean index 42a80f88f..b94af7dcb 100644 --- a/reference-manual/Manual/Meta/LakeToml/Table.lean +++ b/reference-manual/Manual/Meta/LakeToml/Table.lean @@ -71,7 +71,7 @@ def FieldType.toHtml (plural : Bool := false) : FieldType → Html | .option t => t.toHtml ++ " (optional)" | .oneOf xs => let opts := xs - |>.map ({{{{show Html from .text true s!"\"{·}\""}}}}) + |>.map ({{{{show Html from .text s!"\"{·}\""}}}}) |>.intersperse {{", "}} {{"one of " {{opts}} }} diff --git a/reference-manual/Manual/Meta/Syntax.lean b/reference-manual/Manual/Meta/Syntax.lean index d40fd8522..32739fb55 100644 --- a/reference-manual/Manual/Meta/Syntax.lean +++ b/reference-manual/Manual/Meta/Syntax.lean @@ -721,7 +721,7 @@ partial def grammar.descr : BlockDescr := withHighlighting { where bnfHtml : TaggedText GrammarTag → GrammarHtmlM Html - | .text str => pure <| .text true str + | .text str => pure <| .text str | .tag t txt => tagHtml t (bnfHtml txt) | .append txts => .seq <$> txts.mapM bnfHtml diff --git a/reference-manual/Tutorial/Meta/Theme.lean b/reference-manual/Tutorial/Meta/Theme.lean index 23aa16d58..9e4b643db 100644 --- a/reference-manual/Tutorial/Meta/Theme.lean +++ b/reference-manual/Tutorial/Meta/Theme.lean @@ -95,7 +95,7 @@ def footer : FooterConfig := { Helper to create FRO home navigation item -/ def navFroItem (path : Path) : NavBarItem := - { title := .text false "Home" + { title := .raw "Home" , url := some "/fro" , active := path == #["fro"] } @@ -116,15 +116,15 @@ def buildFroNavBarConfig : TemplateM NavBarConfig := do let path ← currentPath let froPathItems (path : Path) : Array NavBarItem := #[ - { title := .text false "About", url := some "/fro/about", active := path == #["fro", "about"] }, - { title := .text false "Team", url := some "/fro/team", active := path == #["fro", "team"] }, - { title := .text false "Roadmap", url := some "/fro/roadmap", active := path == #["fro", "roadmap"] }, - { title := .text false "Contact", url := some "/fro/contact", active := path == #["fro", "contact"] } + { title := .raw "About", url := some "/fro/about", active := path == #["fro", "about"] }, + { title := .raw "Team", url := some "/fro/team", active := path == #["fro", "team"] }, + { title := .raw "Roadmap", url := some "/fro/roadmap", active := path == #["fro", "roadmap"] }, + { title := .raw "Contact", url := some "/fro/contact", active := path == #["fro", "contact"] } ] let externalLinks : Array NavBarItem := #[ - { title := .text false "Playground", url := some "https://live.lean-lang.org/?from=lean", blank := true }, - { title := .text false "Reservoir", url := some "https://reservoir.lean-lang.org/", blank := true } + { title := .raw "Playground", url := some "https://live.lean-lang.org/?from=lean", blank := true }, + { title := .raw "Reservoir", url := some "https://reservoir.lean-lang.org/", blank := true } ] let rightItems : Array NavBarItem := #[ diff --git a/verso-slides/Tests/Render.lean b/verso-slides/Tests/Render.lean index 3e547345a..f4bc53497 100644 --- a/verso-slides/Tests/Render.lean +++ b/verso-slides/Tests/Render.lean @@ -20,6 +20,7 @@ open SubVerso.Highlighting Highlighted open Verso.Code (HighlightHtmlM) open Verso.Code.Hover (State) open Verso Output Html +open Lean (Html) open VersoSlides @@ -48,7 +49,7 @@ def runHighlightHtml (act : HighlightHtmlM Slides Html) : Html := /-- Renders a `SlideCode` to an HTML string. -/ def renderStr (sc : SlideCode) : String := - (runHighlightHtml (sc.toHtml (g := Slides))).asString + (runHighlightHtml (sc.toHtml (g := Slides))).render structure TestState where @@ -226,5 +227,5 @@ where { extraHead := #[{{ }}] } "Deck" (.seq #[]) testHtmlHas "extraHead renders module script" - fullHtml.asString + fullHtml.render s!"" diff --git a/verso-slides/VersoSlides/Directives.lean b/verso-slides/VersoSlides/Directives.lean index 64a20ebdf..6207cb9ae 100644 --- a/verso-slides/VersoSlides/Directives.lean +++ b/verso-slides/VersoSlides/Directives.lean @@ -587,8 +587,8 @@ Usage: @[code_block] public meta def html : CodeBlockExpanderOf Unit | (), str => do - -- The `false` parameter treats the text as unescaped raw HTML data. - let html := Verso.Output.Html.text false str.getVersoCodeBlock + -- `raw` treats the text as unescaped raw HTML data. + let html := Lean.Html.raw str.getVersoCodeBlock ``(Verso.Doc.Block.other (BlockExt.ofHtml $(quote html)) #[]) /-- @@ -606,5 +606,5 @@ public meta def htmlRole : RoleExpanderOf Unit | throwError "Expected a single inline code argument" let some { content := htmlStr, .. } := CodeView.of arg | throwErrorAt arg "Expected inline code" - let html := Verso.Output.Html.text false htmlStr.getVersoCode + let html := Lean.Html.raw htmlStr.getVersoCode ``(Verso.Doc.Inline.other (VersoSlides.InlineExt.ofHtml $(quote html)) #[]) diff --git a/verso-slides/VersoSlides/Render.lean b/verso-slides/VersoSlides/Render.lean index 8ca15adaf..9e6b48df6 100644 --- a/verso-slides/VersoSlides/Render.lean +++ b/verso-slides/VersoSlides/Render.lean @@ -15,6 +15,7 @@ import Illuminate.Animation.Render set_option doc.verso true open Verso Doc Output Html +open Lean (Html) open Verso.Doc.Html (HtmlT GenreHtml ToHtml mkPartHeader) open SubVerso.Highlighting (Highlighted hlFromExport!) open Verso.Code (HighlightHtmlM highlightingStyle highlightingJs) @@ -29,13 +30,13 @@ namespace VersoSlides /-- Pushes a CSS class onto all top-level HTML tags in a fragment. -/ partial def addClassToHtml (cls : String) : Html → Html - | .tag name attrs children => + | .element name attrs children => let attrs := if let some i := attrs.findFinIdx? (·.1 == "class") then attrs.set i ("class", attrs[i].2 ++ " " ++ cls) else attrs.push ("class", cls) - .tag name attrs children + .element name attrs children | .seq elts => .seq (elts.map (addClassToHtml cls)) | other => other @@ -53,9 +54,9 @@ private def pushOneAttr (attrs : Array (String × String)) (k v : String) : Arra /-- Pushes arbitrary attributes onto all top-level HTML tags in a fragment. -/ partial def pushAttrsOntoHtml (newAttrs : Array (String × String)) : Html → Html - | .tag name attrs children => + | .element name attrs children => let attrs := newAttrs.foldl (fun acc (k, v) => pushOneAttr acc k v) attrs - .tag name attrs children + .element name attrs children | .seq elts => .seq (elts.map (pushAttrsOntoHtml newAttrs)) | other => other @@ -111,7 +112,7 @@ instance [Monad m] [MonadBuildLog (HtmlT Slides m)] : GenreHtml Slides m where pure (pushAttrsOntoHtml attrs (.seq inner)) | .wrap attrs => let inner ← contents.mapM blockHtml - pure (.tag "div" attrs (.seq inner)) + pure (.element "div" attrs (.seq inner)) | .ofHtml html => pure html | .slideCode scExport panel stretch => @@ -173,7 +174,7 @@ instance [Monad m] [MonadBuildLog (HtmlT Slides m)] : GenreHtml Slides m where let cells := .seq (← row.mapIdxM (mkCell false ·)) pure {{ {{cells}} }} pure {{ {{.seq trs}} }} - pure (.tag "table" tableAttrs (.seq #[theadHtml, tbodyHtml])) + pure (.element "table" tableAttrs (.seq #[theadHtml, tbodyHtml])) | .css _ => pure .empty | .diagram svgStr cssWidth background => @@ -183,7 +184,7 @@ instance [Monad m] [MonadBuildLog (HtmlT Slides m)] : GenreHtml Slides m where let style := s!"width: {cssWidth}{bgStyle}" pure {{
- {{Html.text false svgStr}} + {{Html.raw svgStr}}
}} | .animate containerId animDataJson cssWidth background fragmentIndices autoplay => @@ -202,7 +203,7 @@ instance [Monad m] [MonadBuildLog (HtmlT Slides m)] : GenreHtml Slides m where let attrs := match idx with | some n => baseAttrs.push ("data-fragment-index", toString n) | none => baseAttrs - .tag "span" attrs .empty + .element "span" attrs .empty let autoplayAttr := if autoplay then "true" else "false" pure {{
{{fragSpans}} }} inline inlineHtml container contents := do @@ -221,10 +222,10 @@ instance [Monad m] [MonadBuildLog (HtmlT Slides m)] : GenreHtml Slides m where let mut attrs : Array (String × String) := #[("class", cls)] if let some i := index then attrs := attrs.push ("data-fragment-index", toString i) - pure (.tag "span" attrs (.seq inner)) + pure (.element "span" attrs (.seq inner)) | .styled attrs => let inner ← contents.mapM inlineHtml - pure (.tag "span" attrs (.seq inner)) + pure (.element "span" attrs (.seq inner)) | .image imgSrcVal alt width height cssClass => let imgSrc ← match imgSrcVal with | .projectRelative resolved => do @@ -247,7 +248,7 @@ instance [Monad m] [MonadBuildLog (HtmlT Slides m)] : GenreHtml Slides m where | (false, some c) => some c | (false, none) => none if let some c := classVal then attrs := attrs.push ("class", c) - pure (.tag "img" attrs .empty) + pure (.element "img" attrs .empty) | .ofHtml html => pure html | .slideCode scExport => @@ -277,7 +278,7 @@ private def blkToHtml (b : Block Slides) : HtmlT Slides m Html := /-- Renders an array of inlines as a heading at the given level. -/ private def renderHeading (level : Nat) (title : Array (Inline Slides)) : HtmlT Slides m Html := do let titleHtml ← title.mapM inlToHtml - pure (.tag s!"h{level}" #[] (.seq titleHtml)) + pure (.element s!"h{level}" #[] (.seq titleHtml)) /-- Returns {name}`true` if a {name}`Part` has any non-empty direct content blocks. -/ private def hasDirectContent (p : Part Slides) : Bool := @@ -301,19 +302,19 @@ partial def renderSlidePart (config : Config) (level : Nat) (parentVertical : Bo let mut slides := #[] -- If there's direct content, create implicit first vertical sub-slide if hasDirectContent p then - slides := slides.push (.tag "section" #[] (.seq (#[heading] ++ contentHtml))) + slides := slides.push (.element "section" #[] (.seq (#[heading] ++ contentHtml))) -- Render each ## sub-part as a vertical sub-slide for sub in p.subParts do slides := slides.push (← renderSlidePart config 1 true sub) - pure (.tag "section" attrs (.seq slides)) + pure (.element "section" attrs (.seq slides)) else -- Single horizontal slide (no vertical sub-slides) let subContent ← p.subParts.mapM (renderSlidePart config 1 false) - pure (.tag "section" attrs (.seq (#[heading] ++ contentHtml ++ subContent))) + pure (.element "section" attrs (.seq (#[heading] ++ contentHtml ++ subContent))) else if level == 1 && parentVertical then -- `##` section under vertical parent: emit as vertical sub-slide (
) let subContent ← p.subParts.mapM (renderSlidePart config 2 false) - pure (.tag "section" attrs (.seq (#[heading] ++ contentHtml ++ subContent))) + pure (.element "section" attrs (.seq (#[heading] ++ contentHtml ++ subContent))) else -- `##` under non-vertical parent, or `###` and deeper: flatten (no
wrapper) let subContent ← p.subParts.mapM (renderSlidePart config (level + 1) false) @@ -445,7 +446,7 @@ def renderFullHtml (config : Config) (title : String) (slidesBody : Html) (custo if config.mathPrelude.isEmpty then #[] else let js := s!"window.__versoMathPrelude = {jsString config.mathPrelude};" - #[{{ }}] + #[{{ }}] let themeHref := match config.theme with | .builtin name => s!"{libPrefix}/reveal.js/dist/theme/{name}.css" | .custom theme => theme.stylesheet.filename @@ -493,7 +494,7 @@ def renderFullHtml (config : Config) (title : String) (slidesBody : Html) (custo - {{ customCss.map fun css => {{ }} }} + {{ customCss.map fun css => {{ }} }} {{config.extraHead}} @@ -509,7 +510,7 @@ def renderFullHtml (config : Config) (title : String) (slidesBody : Html) (custo {{mathPreludeScripts}} {{extraJsScripts}} - + @@ -698,7 +699,7 @@ def slidesMain (config : Config := {}) (doc : Part Slides) : IO UInt32 := runWit if !(← dir.pathExists) then IO.FS.createDirAll dir let indexPath := dir / "index.html" - IO.FS.writeFile indexPath ("\n" ++ fullHtml.asString) + IO.FS.writeFile indexPath ("\n" ++ fullHtml.render) -- Write hover data JSON for highlighted code tooltips let docsJsonPath := dir / "-verso-docs.json" diff --git a/verso-slides/VersoSlides/SlideCode/Render.lean b/verso-slides/VersoSlides/SlideCode/Render.lean index 41a76feb6..2f3f48990 100644 --- a/verso-slides/VersoSlides/SlideCode/Render.lean +++ b/verso-slides/VersoSlides/SlideCode/Render.lean @@ -15,6 +15,7 @@ Renders SlideCode trees to HTML for `reveal.js`. open Verso Output Html +open Lean (Html) open SubVerso.Highlighting (Highlighted) open Verso.Code (HighlightHtmlM) open Lean (Json toJson) @@ -96,7 +97,7 @@ public def SlideCode.toHtml : SlideCode → HighlightHtmlM g Html pure {{ {{contentHtml}} - {{Html.tag "span" (#[("class", "tactic-state"), ("style", "display:none")] ++ fmtAttr) goalsHtml}} + {{Html.element "span" (#[("class", "tactic-state"), ("style", "display:none")] ++ fmtAttr) goalsHtml}} }} | .span info content => do @@ -118,17 +119,17 @@ public def SlideCode.toHtml : SlideCode → HighlightHtmlM g Html }} | .fragment w true content => do let contentHtml ← content.toHtml - pure (Html.tag "div" (#[("class", fragClass w)] ++ fragIndexAttr w) contentHtml) + pure (Html.element "div" (#[("class", fragClass w)] ++ fragIndexAttr w) contentHtml) | .fragment w false content => do let contentHtml ← content.toHtml - pure (Html.tag "span" (#[("class", fragClass w)] ++ fragIndexAttr w) contentHtml) + pure (Html.element "span" (#[("class", fragClass w)] ++ fragIndexAttr w) contentHtml) | .click target index => do let targetHtml ← target.toHtml let cls := "fragment slide-click-only" let attrs := match index with | some i => #[("class", cls), ("data-fragment-index", toString i)] | none => #[("class", cls)] - pure (Html.tag "span" attrs targetHtml) + pure (Html.element "span" attrs targetHtml) | .commandOutput info => do -- Use the highest severity for the wrapper class let severity := info.foldl (fun acc (s, _) => match acc, s with diff --git a/verso-web-components/VersoWeb/Components/ArchiveEntry.lean b/verso-web-components/VersoWeb/Components/ArchiveEntry.lean index a89e0f57e..065e13f9a 100644 --- a/verso-web-components/VersoWeb/Components/ArchiveEntry.lean +++ b/verso-web-components/VersoWeb/Components/ArchiveEntry.lean @@ -11,6 +11,7 @@ import VersoWeb.Util namespace Verso.Web.Components open Verso.Output Html +open Lean (Html) open Verso.Genre.Blog Template /-- @@ -19,7 +20,7 @@ Render the metadata section (authors and date) private def renderArchiveMetadata (md : Post.PartMetadata) : Html := {{