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">
<div class="goal-hyps">
<span class="hyp-type">
<var>{tyi.name}<//var>
<b>: <//b>
<span>{tyi.type}<//span>
<//span>
<//div>
<//blockquote>
<//div>
<//small>
<//div>
<var>{tyi.name}</var>
<b>: </b>
<span>{tyi.type}</span>
</span>
</div>
</blockquote>
</div>
</small>
</div>
def Token.processSemantic (t : Token) : Html :=
match t.semanticType with
| some "Name.Attribute" => <span class="na">{t.raw}<//span>
| some "Name.Variable" => <span class="nv">{t.raw}<//span>
| some "Keyword" => <span class="k">{t.raw}<//span>
| some "Name.Attribute" => <span class="na">{t.raw}</span>
| some "Name.Variable" => <span class="nv">{t.raw}</span>
| some "Keyword" => <span class="k">{t.raw}</span>
| _ => Html.text t.raw
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
<span class="alectryon-token">
[parts]
<//span>
</span>
def Contents.toHtml : Contents → AlectryonM Html
| .string value =>
pure
<span class="alectryon-wsp">
{value}
<//span>
</span>
| .experimentalTokens values => do
let values ← values.mapM Token.toHtml
pure
<span class="alectryon-wsp">
[values]
<//span>
</span>
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
hypParts := hypParts.push
<span class="hyp-body">
<b>:= <//b>
<span>{h.body}<//span>
<//span>
<b>:= </b>
<span>{h.body}</span>
</span>
hypParts := hypParts.push
<span class="hyp-type">
<b>: <//b>
<span >{h.type}<//span>
<//span>
<b>: </b>
<span >{h.type}</span>
</span>
pure
<span>
[hypParts]
<//span>
</span>
def Goal.toHtml (g : Goal) : AlectryonM Html := do
let mut hypotheses := #[]
@ -107,21 +107,21 @@ def Goal.toHtml (g : Goal) : AlectryonM Html := do
<blockquote class="alectryon-goal">
<div class="goal-hyps">
[hypotheses]
<//div>
</div>
<span class="goal-separator">
<hr><span class="goal-name">{g.name}<//span><//hr>
<//span>
<hr><span class="goal-name">{g.name}</span></hr>
</span>
<div class="goal-conclusion">
{g.conclusion}
<//div>
<//blockquote>
</div>
</blockquote>
def Message.toHtml (m : Message) : AlectryonM Html := do
pure
<blockquote class="alectryon-message">
-- TODO: This might have to be done in a fancier way
{m.contents}
<//blockquote>
</blockquote>
def Sentence.toHtml (s : Sentence) : AlectryonM Html := do
let messages :=
@ -129,7 +129,7 @@ def Sentence.toHtml (s : Sentence) : AlectryonM Html := do
#[
<div class="alectryon-messages">
[←s.messages.mapM Message.toHtml]
<//div>
</div>
]
else
#[]
@ -140,7 +140,7 @@ def Sentence.toHtml (s : Sentence) : AlectryonM Html := do
#[
<div class="alectryon-goals">
[←s.goals.mapM Goal.toHtml]
<//div>
</div>
]
else
#[]
@ -152,12 +152,12 @@ def Sentence.toHtml (s : Sentence) : AlectryonM Html := do
<input class="alectryon-toggle" id={buttonLabel} style="display: none" type="checkbox"/>
<label class="alectryon-input" for={buttonLabel}>
{←s.contents.toHtml}
<//label>
</label>
<small class="alectryon-output">
[messages]
[goals]
<//small>
<//span>
</small>
</span>
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
let banner :=
<div «class»="alectryon-banner">
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.
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>.
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.
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>.
</div>
pure

View File

@ -183,13 +183,13 @@ partial def infoFormatToHtml (i : CodeWithInfos) : HtmlM (Array Html) := do
match t with
| TaggedText.text 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]
| _ =>
-- 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 #[Html.element "span" true #[("class", "fn")] (←infoFormatToHtml t)]
pure #[<span class="fn">[←infoFormatToHtml t]</span>]
| _ => pure #[<span class="fn">[←infoFormatToHtml t]</span>]
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} : "]
nodes := nodes.append (←infoFormatToHtml arg.type)
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]
if implicit then
pure <span class="impl_arg">{html}</span>
@ -53,7 +53,7 @@ def structureInfoHeader (s : Process.StructureInfo) : HtmlM (Array Html) := do
let mut parents := #[]
for parent in s.parents do
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]
parents := parents.push html
nodes := nodes.append (parents.toList.intersperse (Html.text ", ")).toArray
@ -65,7 +65,7 @@ and name.
-/
def docInfoHeader (doc : DocInfo) : HtmlM Html := do
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
<span class="decl_name">
<a class="break_within" href={←declNameToLink doc.getName}>
@ -82,7 +82,7 @@ def docInfoHeader (doc : DocInfo) : HtmlM Html := do
| _ => nodes := nodes
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>
/--

View File

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

View File

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

View File

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