From 9f50966339d1d3bbe50305ba50cf3e293d3ed7a9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20B=C3=B6ving?= Date: Mon, 20 Jun 2022 18:39:55 +0200 Subject: [PATCH] feat: initial LeanInk HTML generation --- DocGen4/LeanInk/Output.lean | 158 +++++- DocGen4/Output.lean | 32 +- DocGen4/Output/Base.lean | 4 + DocGen4/Output/ToHtmlFormat.lean | 34 +- static/alectryon/alectryon.css | 777 ++++++++++++++++++++++++++++ static/alectryon/alectryon.js | 172 ++++++ static/alectryon/docutils_basic.css | 593 +++++++++++++++++++++ 7 files changed, 1729 insertions(+), 41 deletions(-) create mode 100644 static/alectryon/alectryon.css create mode 100644 static/alectryon/alectryon.js create mode 100644 static/alectryon/docutils_basic.css diff --git a/DocGen4/LeanInk/Output.lean b/DocGen4/LeanInk/Output.lean index 41986d9..91db9b6 100644 --- a/DocGen4/LeanInk/Output.lean +++ b/DocGen4/LeanInk/Output.lean @@ -14,27 +14,151 @@ namespace LeanInk.Annotation.Alectryon open DocGen4 Output open scoped DocGen4.Jsx -def TypeInfo.toHtml : TypeInfo → HtmlM Html := sorry +structure AlectryonContext where + counter : Nat -def Token.toHtml : Token → HtmlM Html := sorry +abbrev AlectryonM := StateT AlectryonContext HtmlM -def Contents.toHtml : Contents → HtmlM Html - | .string value => sorry - | .experimentalTokens value => sorry +def getNextButtonLabel : AlectryonM String := do + let val ← get + let newCounter := val.counter + 1 + set { val with counter := newCounter } + pure s!"plain-lean4-lean-chk{val.counter}" -def Hypothesis.toHtml : Hypothesis → HtmlM Html := sorry +def TypeInfo.toHtml : TypeInfo → AlectryonM Html := sorry -def Goal.toHtml : Goal → HtmlM Html := sorry +def Token.toHtml (t : Token) : AlectryonM Html := do + -- TODO: Show rest of token + pure $ Html.text t.raw -def Message.toHtml : Message → HtmlM Html := sorry +def Contents.toHtml : Contents → AlectryonM (Array Html) + | .string value => pure #[Html.text value] + | .experimentalTokens values => values.mapM Token.toHtml -def Sentence.toHtml : Sentence → HtmlM Html := sorry +def Hypothesis.toHtml (h : Hypothesis) : AlectryonM Html := do + let mut hypParts := #[[h.names.intersperse ", " |>.map Html.text |>.toArray]] + if h.body != "" then + hypParts := hypParts.push + + := + {h.body} + + hypParts := hypParts.push + + : + {h.type} + -def Text.toHtml : Text → HtmlM Html := sorry + pure + + [hypParts] + -def Fragment.toHtml : Fragment → HtmlM Html - | .text value => sorry - | .sentence value => sorry +def Goal.toHtml (g : Goal) : AlectryonM Html := do + let mut hypotheses := #[] + for hyp in g.hypotheses do + let rendered ← hyp.toHtml + hypotheses := hypotheses.push rendered + hypotheses := hypotheses.push
+ pure +
+
+ [hypotheses] + + +
{g.name} + +
+ {g.conclusion} + + + +def Message.toHtml (m : Message) : AlectryonM Html := do + pure +
+ -- TODO: This might have to be done in a fancier way + {m.contents} + + +def Sentence.toHtml (s : Sentence) : AlectryonM Html := do + let messages := + if s.messages.size > 0 then + #[ +
+ [←s.messages.mapM Message.toHtml] + + ] + else + #[] + + let goals := + if s.goals.size > 0 then + -- TODO: Alectryon has a "alectryon-extra-goals" here, implement it + #[ +
+ [←s.goals.mapM Goal.toHtml] + + ] + else + #[] + + let buttonLabel ← getNextButtonLabel + + pure + + +