chore: Cleanup HTML syntax and pretty printing

main
Henrik Böving 2022-06-21 20:54:29 +02:00
parent 38e02c5f65
commit 5b56be76f2
6 changed files with 54 additions and 59 deletions

View File

@ -33,21 +33,21 @@ def TypeInfo.toHtml (tyi : TypeInfo) : AlectryonM Html := do
<blockquote class="alectryon-goal"> <blockquote class="alectryon-goal">
<div class="goal-hyps"> <div class="goal-hyps">
<span class="hyp-type"> <span class="hyp-type">
<var>{tyi.name}<//var> <var>{tyi.name}</var>
<b>: <//b> <b>: </b>
<span>{tyi.type}<//span> <span>{tyi.type}</span>
<//span> </span>
<//div> </div>
<//blockquote> </blockquote>
<//div> </div>
<//small> </small>
<//div> </div>
def Token.processSemantic (t : Token) : Html := def Token.processSemantic (t : Token) : Html :=
match t.semanticType with match t.semanticType with
| some "Name.Attribute" => <span class="na">{t.raw}<//span> | some "Name.Attribute" => <span class="na">{t.raw}</span>
| some "Name.Variable" => <span class="nv">{t.raw}<//span> | some "Name.Variable" => <span class="nv">{t.raw}</span>
| some "Keyword" => <span class="k">{t.raw}<//span> | some "Keyword" => <span class="k">{t.raw}</span>
| _ => Html.text t.raw | _ => Html.text t.raw
def Token.toHtml (t : Token) : AlectryonM Html := do def Token.toHtml (t : Token) : AlectryonM Html := do
@ -63,39 +63,39 @@ def Token.toHtml (t : Token) : AlectryonM Html := do
-- TODO: Show rest of token -- TODO: Show rest of token
<span class="alectryon-token"> <span class="alectryon-token">
[parts] [parts]
<//span> </span>
def Contents.toHtml : Contents → AlectryonM Html def Contents.toHtml : Contents → AlectryonM Html
| .string value => | .string value =>
pure pure
<span class="alectryon-wsp"> <span class="alectryon-wsp">
{value} {value}
<//span> </span>
| .experimentalTokens values => do | .experimentalTokens values => do
let values ← values.mapM Token.toHtml let values ← values.mapM Token.toHtml
pure pure
<span class="alectryon-wsp"> <span class="alectryon-wsp">
[values] [values]
<//span> </span>
def Hypothesis.toHtml (h : Hypothesis) : AlectryonM Html := do def Hypothesis.toHtml (h : Hypothesis) : AlectryonM Html := do
let mut hypParts := #[<var>[h.names.intersperse ", " |>.map Html.text |>.toArray]<//var>] let mut hypParts := #[<var>[h.names.intersperse ", " |>.map Html.text |>.toArray]</var>]
if h.body != "" then if h.body != "" then
hypParts := hypParts.push hypParts := hypParts.push
<span class="hyp-body"> <span class="hyp-body">
<b>:= <//b> <b>:= </b>
<span>{h.body}<//span> <span>{h.body}</span>
<//span> </span>
hypParts := hypParts.push hypParts := hypParts.push
<span class="hyp-type"> <span class="hyp-type">
<b>: <//b> <b>: </b>
<span >{h.type}<//span> <span >{h.type}</span>
<//span> </span>
pure pure
<span> <span>
[hypParts] [hypParts]
<//span> </span>
def Goal.toHtml (g : Goal) : AlectryonM Html := do def Goal.toHtml (g : Goal) : AlectryonM Html := do
let mut hypotheses := #[] let mut hypotheses := #[]
@ -107,21 +107,21 @@ def Goal.toHtml (g : Goal) : AlectryonM Html := do
<blockquote class="alectryon-goal"> <blockquote class="alectryon-goal">
<div class="goal-hyps"> <div class="goal-hyps">
[hypotheses] [hypotheses]
<//div> </div>
<span class="goal-separator"> <span class="goal-separator">
<hr><span class="goal-name">{g.name}<//span><//hr> <hr><span class="goal-name">{g.name}</span></hr>
<//span> </span>
<div class="goal-conclusion"> <div class="goal-conclusion">
{g.conclusion} {g.conclusion}
<//div> </div>
<//blockquote> </blockquote>
def Message.toHtml (m : Message) : AlectryonM Html := do def Message.toHtml (m : Message) : AlectryonM Html := do
pure pure
<blockquote class="alectryon-message"> <blockquote class="alectryon-message">
-- TODO: This might have to be done in a fancier way -- TODO: This might have to be done in a fancier way
{m.contents} {m.contents}
<//blockquote> </blockquote>
def Sentence.toHtml (s : Sentence) : AlectryonM Html := do def Sentence.toHtml (s : Sentence) : AlectryonM Html := do
let messages := let messages :=
@ -129,7 +129,7 @@ def Sentence.toHtml (s : Sentence) : AlectryonM Html := do
#[ #[
<div class="alectryon-messages"> <div class="alectryon-messages">
[←s.messages.mapM Message.toHtml] [←s.messages.mapM Message.toHtml]
<//div> </div>
] ]
else else
#[] #[]
@ -140,7 +140,7 @@ def Sentence.toHtml (s : Sentence) : AlectryonM Html := do
#[ #[
<div class="alectryon-goals"> <div class="alectryon-goals">
[←s.goals.mapM Goal.toHtml] [←s.goals.mapM Goal.toHtml]
<//div> </div>
] ]
else else
#[] #[]
@ -152,12 +152,12 @@ def Sentence.toHtml (s : Sentence) : AlectryonM Html := do
<input class="alectryon-toggle" id={buttonLabel} style="display: none" type="checkbox"/> <input class="alectryon-toggle" id={buttonLabel} style="display: none" type="checkbox"/>
<label class="alectryon-input" for={buttonLabel}> <label class="alectryon-input" for={buttonLabel}>
{←s.contents.toHtml} {←s.contents.toHtml}
<//label> </label>
<small class="alectryon-output"> <small class="alectryon-output">
[messages] [messages]
[goals] [goals]
<//small> </small>
<//span> </span>
def Text.toHtml (t : Text) : AlectryonM Html := t.contents.toHtml def Text.toHtml (t : Text) : AlectryonM Html := t.contents.toHtml
@ -168,10 +168,10 @@ def Fragment.toHtml : Fragment → AlectryonM Html
def baseHtml (content : Array Html) : AlectryonM Html := do def baseHtml (content : Array Html) : AlectryonM Html := do
let banner := let banner :=
<div «class»="alectryon-banner"> <div «class»="alectryon-banner">
Built with <a href="https://github.com/leanprover/doc-gen4">doc-gen4<//a>, running Lean4. Built with <a href="https://github.com/leanprover/doc-gen4">doc-gen4</a>, running Lean4.
Bubbles (<span class="alectryon-bubble"><//span>) indicate interactive fragments: hover for details, tap to reveal contents. Bubbles (<span class="alectryon-bubble"></span>) indicate interactive fragments: hover for details, tap to reveal contents.
Use <kbd>Ctrl+↑<//kbd> <kbd>Ctrl+↓<//kbd> to navigate, <kbd>Ctrl+🖱️<//kbd> to focus. Use <kbd>Ctrl+↑</kbd> <kbd>Ctrl+↓</kbd> to navigate, <kbd>Ctrl+🖱️</kbd> to focus.
On Mac, use <kbd>Cmd<//kbd> instead of <kbd>Ctrl<//kbd>. On Mac, use <kbd>Cmd</kbd> instead of <kbd>Ctrl</kbd>.
</div> </div>
pure pure

View File

@ -183,13 +183,13 @@ partial def infoFormatToHtml (i : CodeWithInfos) : HtmlM (Array Html) := do
match t with match t with
| TaggedText.text t => | TaggedText.text t =>
let (front, t, back) := splitWhitespaces $ Html.escape t let (front, t, back) := splitWhitespaces $ Html.escape t
let elem := Html.element "a" true #[("href", ←declNameToLink name)] #[t] let elem := <a href={←declNameToLink name}>{t}</a>
pure #[Html.text front, elem, Html.text back] pure #[Html.text front, elem, Html.text back]
| _ => | _ =>
-- TODO: Is this ever reachable? -- TODO: Is this ever reachable?
pure #[Html.element "a" true #[("href", ←declNameToLink name)] (←infoFormatToHtml t)] pure #[<a href={←declNameToLink name}>[←infoFormatToHtml t]</a>]
| _ => | _ =>
pure #[Html.element "span" true #[("class", "fn")] (←infoFormatToHtml t)] pure #[<span class="fn">[←infoFormatToHtml t]</span>]
| _ => pure #[Html.element "span" true #[("class", "fn")] (←infoFormatToHtml t)] | _ => pure #[<span class="fn">[←infoFormatToHtml t]</span>]
end DocGen4.Output end DocGen4.Output

View File

@ -35,7 +35,7 @@ def argToHtml (arg : Arg) : HtmlM Html := do
let mut nodes := #[Html.text s!"{l}{arg.name.toString} : "] let mut nodes := #[Html.text s!"{l}{arg.name.toString} : "]
nodes := nodes.append (←infoFormatToHtml arg.type) nodes := nodes.append (←infoFormatToHtml arg.type)
nodes := nodes.push r nodes := nodes.push r
let inner := Html.element "span" true #[("class", "fn")] nodes let inner := <span class="fn">[nodes]</span>
let html := Html.element "span" false #[("class", "decl_args")] #[inner] let html := Html.element "span" false #[("class", "decl_args")] #[inner]
if implicit then if implicit then
pure <span class="impl_arg">{html}</span> pure <span class="impl_arg">{html}</span>
@ -53,7 +53,7 @@ def structureInfoHeader (s : Process.StructureInfo) : HtmlM (Array Html) := do
let mut parents := #[] let mut parents := #[]
for parent in s.parents do for parent in s.parents do
let link ← declNameToHtmlBreakWithinLink parent let link ← declNameToHtmlBreakWithinLink parent
let inner := Html.element "span" true #[("class", "fn")] #[link] let inner := <span class="fn">{link}</span>
let html:= Html.element "span" false #[("class", "decl_parent")] #[inner] let html:= Html.element "span" false #[("class", "decl_parent")] #[inner]
parents := parents.push html parents := parents.push html
nodes := nodes.append (parents.toList.intersperse (Html.text ", ")).toArray nodes := nodes.append (parents.toList.intersperse (Html.text ", ")).toArray
@ -65,7 +65,7 @@ and name.
-/ -/
def docInfoHeader (doc : DocInfo) : HtmlM Html := do def docInfoHeader (doc : DocInfo) : HtmlM Html := do
let mut nodes := #[] let mut nodes := #[]
nodes := nodes.push <span class="decl_kind">{doc.getKindDescription}</span> nodes := nodes.push $ Html.element "span" false #[("class", "decl_kind")] #[doc.getKindDescription]
nodes := nodes.push nodes := nodes.push
<span class="decl_name"> <span class="decl_name">
<a class="break_within" href={←declNameToLink doc.getName}> <a class="break_within" href={←declNameToLink doc.getName}>
@ -82,7 +82,7 @@ def docInfoHeader (doc : DocInfo) : HtmlM Html := do
| _ => nodes := nodes | _ => nodes := nodes
nodes := nodes.push <span class="decl_args">:</span> nodes := nodes.push <span class="decl_args">:</span>
nodes := nodes.push $ Html.element "div" true #[("class", "decl_type")] (←infoFormatToHtml doc.getType) nodes := nodes.push <div class="decl_type">[←infoFormatToHtml doc.getType]</div>
pure <div class="decl_header"> [nodes] </div> pure <div class="decl_header"> [nodes] </div>
/-- /--

View File

@ -29,15 +29,15 @@ partial def moduleListDir (h : Hierarchy) : HtmlM Html := do
let dirNodes ← (dirs.mapM moduleListDir) let dirNodes ← (dirs.mapM moduleListDir)
let fileNodes ← (files.mapM moduleListFile) let fileNodes ← (files.mapM moduleListFile)
let moduleLink ← moduleNameToLink h.getName let moduleLink ← moduleNameToLink h.getName
let summary :=
if (←getResult).moduleInfo.contains h.getName then
<summary>{←moduleToHtmlLink h.getName}</summary>
else
<summary>{h.getName.toString}</summary>
pure pure
<details class="nav_sect" "data-path"={moduleLink} <details class="nav_sect" "data-path"={moduleLink} [if (←getCurrentName).any (h.getName.isPrefixOf ·) then #[("open", "")] else #[]]>
[if (←getCurrentName).any (h.getName.isPrefixOf ·) then #[("open", "")] else #[]]> {summary}
{
if (←getResult).moduleInfo.contains h.getName then
Html.element "summary" true #[] #[←moduleToHtmlLink h.getName]
else
<summary>{h.getName.toString}</summary>
}
[dirNodes] [dirNodes]
[fileNodes] [fileNodes]
</details> </details>

View File

@ -89,7 +89,6 @@ syntax jsxAttr := jsxSimpleAttr <|> jsxAttrSpread
syntax "<" rawIdent jsxAttr* "/>" : jsxElement syntax "<" rawIdent jsxAttr* "/>" : jsxElement
syntax "<" rawIdent jsxAttr* ">" jsxChild* "</" rawIdent ">" : jsxElement syntax "<" rawIdent jsxAttr* ">" jsxChild* "</" rawIdent ">" : jsxElement
syntax "<" rawIdent jsxAttr* ">" jsxChild* "<//" rawIdent ">" : jsxElement
syntax jsxText : jsxChild syntax jsxText : jsxChild
syntax "{" term "}" : jsxChild syntax "{" term "}" : jsxChild
@ -135,9 +134,6 @@ macro_rules
| `(<$n $attrs* />) => do | `(<$n $attrs* />) => do
`(Html.element $(quote (toString n.getId)) true $(← translateAttrs attrs) #[]) `(Html.element $(quote (toString n.getId)) true $(← translateAttrs attrs) #[])
| `(<$n $attrs* >$children*</$m>) => do | `(<$n $attrs* >$children*</$m>) => do
let (tag, children) ← htmlHelper n children m
`(Html.element $(quote tag) false $(← translateAttrs attrs) $children)
| `(<$n $attrs* >$children*<//$m>) => do
let (tag, children) ← htmlHelper n children m let (tag, children) ← htmlHelper n children m
`(Html.element $(quote tag) true $(← translateAttrs attrs) $children) `(Html.element $(quote tag) true $(← translateAttrs attrs) $children)

View File

@ -5,7 +5,6 @@ import Cli
open DocGen4 Lean Cli open DocGen4 Lean Cli
def runDocGenCmd (p : Parsed) : IO UInt32 := do def runDocGenCmd (p : Parsed) : IO UInt32 := do
IO.println s!"{p}"
let modules : List String := p.variableArgsAs! String |>.toList let modules : List String := p.variableArgsAs! String |>.toList
let res ← lakeSetup modules let res ← lakeSetup modules
match res with match res with