feat: basic docstring support

main
Xubai Wang 2022-02-15 19:27:12 +08:00
parent 28dfc14530
commit 8da2e2a63d
4 changed files with 34 additions and 15 deletions

View File

@ -1,3 +1,4 @@
import CMark
import DocGen4.Output.Template
namespace DocGen4
@ -23,11 +24,14 @@ def equationsToHtml (i : DefinitionInfo) : HtmlM (Option Html) := do
pure none
def definitionToHtml (i : DefinitionInfo) : HtmlM (Array Html) := do
let equationsHtml ← equationsToHtml i
if let some equationsHtml := equationsHtml then
pure #[equationsHtml]
else
pure #[]
let equationsHtml? ← equationsToHtml i
let docstringHtml? := i.doc.map λ s => Html.text (CMark.renderHtml s)
match equationsHtml?, docstringHtml? with
| some e, some d => pure #[e, d]
| some e, none => pure #[e]
| none , some e => pure #[e]
| none , none => pure #[]
end Output
end DocGen4

View File

@ -1,3 +1,4 @@
import CMark
import DocGen4.Output.Template
namespace DocGen4
@ -11,7 +12,11 @@ def ctorToHtml (i : NameInfo) : HtmlM Html := do
pure <li «class»="constructor" id={name}>{shortName} : [←infoFormatToHtml i.type]</li>
def inductiveToHtml (i : InductiveInfo) : HtmlM (Array Html) := do
pure #[<ul "class"="constructors">[← i.ctors.toArray.mapM ctorToHtml]</ul>]
let constructorsHtml := <ul "class"="constructors">[← i.ctors.toArray.mapM ctorToHtml]</ul>
let docstringHtml? := i.doc.map λ s => Html.text (CMark.renderHtml s)
match docstringHtml? with
| some d => pure #[constructorsHtml, d]
| none => pure #[constructorsHtml]
end Output
end DocGen4

View File

@ -1,3 +1,4 @@
import CMark
import DocGen4.Output.Template
namespace DocGen4
@ -12,21 +13,24 @@ def fieldToHtml (f : NameInfo) : HtmlM Html := do
pure <li «class»="structure_field" id={name}>{s!"{shortName} "} : [←infoFormatToHtml f.type]</li>
def structureToHtml (i : StructureInfo) : HtmlM (Array Html) := do
if Name.isSuffixOf `mk i.ctor.name then
pure #[
<ul «class»="structure_fields" id={i.ctor.name.toString}>
let structureHtml :=
if Name.isSuffixOf `mk i.ctor.name then
(<ul «class»="structure_fields" id={i.ctor.name.toString}>
[←i.fieldInfo.mapM fieldToHtml]
</ul>]
else
let ctorShortName := i.ctor.name.components'.head!.toString
pure #[
<ul «class»="structure_ext">
</ul>)
else
let ctorShortName := i.ctor.name.components'.head!.toString
(<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>
<li «class»="structure_ext_ctor">)</li>
</ul>]
</ul>)
let docstringHtml? := i.doc.map λ s => Html.text (CMark.renderHtml s)
match docstringHtml? with
| some d => pure #[structureHtml, d]
| none => pure #[structureHtml]
end Output
end DocGen4

View File

@ -4,4 +4,10 @@ open Lake DSL
package «doc-gen4» {
-- add configuration options here
supportInterpreter := true
dependencies := #[
{
name := `CMark
src := Source.git "https://github.com/xubaiw/CMark.lean" "925f2ab"
}
]
}