bookshelf-doc/DocGen4/Output/Structure.lean

45 lines
1.4 KiB
Plaintext
Raw Normal View History

import DocGen4.Output.Template
2022-02-17 05:47:38 +00:00
import DocGen4.Output.DocString
namespace DocGen4
namespace Output
open scoped DocGen4.Jsx
open Lean
def fieldToHtml (f : NameInfo) : HtmlM Html := do
let shortName := f.name.components'.head!.toString
let name := f.name.toString
if let some doc := f.doc then
let renderedDoc ← docStringToHtml doc
pure
2022-05-19 09:14:47 +00:00
<li id={name} class="structure_field">
<div class="structure_field_doc">[renderedDoc]</div>
<div class="structure_field_info">{s!"{shortName} "} : [←infoFormatToHtml f.type]</div>
</li>
else
pure
2022-05-19 09:14:47 +00:00
<li id={name} class="structure_field">
<div class="structure_field_info">{s!"{shortName} "} : [←infoFormatToHtml f.type]</div>
</li>
def structureToHtml (i : StructureInfo) : HtmlM (Array Html) := do
2022-02-15 11:27:12 +00:00
let structureHtml :=
if Name.isSuffixOf `mk i.ctor.name then
2022-05-19 09:14:47 +00:00
(<ul class="structure_fields" id={i.ctor.name.toString}>
2022-02-12 14:09:13 +00:00
[←i.fieldInfo.mapM fieldToHtml]
2022-02-15 11:27:12 +00:00
</ul>)
else
let ctorShortName := i.ctor.name.components'.head!.toString
2022-05-19 09:14:47 +00:00
(<ul class="structure_ext">
<li id={i.ctor.name.toString} class="structure_ext_ctor">{s!"{ctorShortName} "} :: (</li>
<ul class="structure_ext_fields">
[←i.fieldInfo.mapM fieldToHtml]
</ul>
2022-05-19 09:14:47 +00:00
<li class="structure_ext_ctor">)</li>
2022-02-15 11:27:12 +00:00
</ul>)
2022-02-18 03:28:44 +00:00
pure #[structureHtml]
end Output
end DocGen4