PhysLean/HepLean/Meta/Notes/HTMLNote.lean

78 lines
2.5 KiB
Text
Raw Normal View History

2024-12-04 13:37:23 +00:00
/-
Copyright (c) 2024 Joseph Tooby-Smith. All rights reserved.
Released under Apache 2.0 license.
Authors: Joseph Tooby-Smith
-/
-- import DocGen4.Output.DocString
import HepLean.Meta.Informal.Post
import HepLean.Meta.Notes.NoteFile
2024-12-04 13:37:23 +00:00
/-!
## Turns a delaration into a html note structure.
-/
namespace HepLean
open Lean
2024-12-04 13:37:23 +00:00
2024-12-04 16:24:23 +00:00
/-- A `HTMLNote` is a structure containing the html information from
2025-01-14 00:11:25 +01:00
individual contributions (commands, informal commands, note ..) etc. to a note file. -/
2024-12-04 13:37:23 +00:00
structure HTMLNote where
2024-12-04 16:24:23 +00:00
/-- The name of the file the contribution came from. -/
2024-12-04 13:37:23 +00:00
fileName : Name
2024-12-04 16:24:23 +00:00
/-- The html contribution of the content. -/
2024-12-04 13:37:23 +00:00
content : String
2024-12-04 16:24:23 +00:00
/-- The line in the file where the contribution came from. -/
2024-12-04 13:37:23 +00:00
line : Nat
2024-12-04 16:24:23 +00:00
/-- Converts a note infor into a HTMLNote. -/
def HTMLNote.ofNodeInfo (ni : NoteInfo) : HTMLNote :=
{ ni with }
2024-12-04 13:37:23 +00:00
2024-12-04 16:24:23 +00:00
/-- An formal definition or lemma to html for a note. -/
def HTMLNote.ofFormal (name : Name) : CoreM HTMLNote := do
let line ← name.lineNumber
let fileName ← name.fileName
return {
fileName, line,
content := s!"
<div class=\"code-block-container\">
<a href=\"{fileName.toGitHubLink line}\" class=\"code-button\">View/Improve</a>
<pre><code>{← name.getDeclString}</code></pre>
</div>"
}
2024-12-04 13:37:23 +00:00
2024-12-04 16:24:23 +00:00
/-- An informal definition or lemma to html for a note. -/
unsafe def HTMLNote.ofInformal (name : Name) : CoreM HTMLNote := do
let line ← name.lineNumber
let fileName ← name.fileName
let constInfo ← getConstInfoDefn name
let webAddress := fileName.toGitHubLink line
2024-12-04 13:37:23 +00:00
let mut content := ""
if constInfo.type.isConstOf ``InformalDefinition then
let doc ← name.getDocString
-- let html ← DocGen4.Output.docStringToHtml doc name.toString
-- let X ← Informal.constantInfoToInformalDefinition constInfo
-- let fragment := X.math.replace "\n" "<br>"
let fragment := doc.replace "\n" "<br>"
content := s!"
<div class=\"informal-def\">
<a href=\"{webAddress}\" class=\"button\">Improve/Formalize</a>
<b>Informal definition:</b> {name}<br>
{fragment}
</div>"
else if constInfo.type.isConstOf ``InformalLemma then
-- let X ← Informal.constantInfoToInformalLemma constInfo
-- let fragment := X.math.replace "\n" "<br>"
let doc ← name.getDocString
let fragment := doc.replace "\n" "<br>"
content := s!"
<div class=\"informal-def\">
<a href=\"{webAddress}\" class=\"button\">Improve/Formalize</a>
<b>Informal lemma:</b> {name}<br>
{fragment}
</div>"
return { content, fileName, line }
2024-12-04 13:37:23 +00:00
end HepLean