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

View File

@ -1,3 +1,4 @@
import CMark
import DocGen4.Output.Template import DocGen4.Output.Template
namespace DocGen4 namespace DocGen4
@ -11,7 +12,11 @@ def ctorToHtml (i : NameInfo) : HtmlM Html := do
pure <li «class»="constructor" id={name}>{shortName} : [←infoFormatToHtml i.type]</li> pure <li «class»="constructor" id={name}>{shortName} : [←infoFormatToHtml i.type]</li>
def inductiveToHtml (i : InductiveInfo) : HtmlM (Array Html) := do 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 Output
end DocGen4 end DocGen4

View File

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

View File

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