Skip to content

Commit

Permalink
feat: add MarkdownDisplay
Browse files Browse the repository at this point in the history
  • Loading branch information
Vtec234 committed Oct 17, 2024
1 parent baa65c6 commit 20c4298
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
21 changes: 21 additions & 0 deletions ProofWidgets/Component/Basic.lean
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,27 @@ def InteractiveMessage : Component InteractiveMessageProps where
}
"

structure MarkdownDisplay.Props where
contents : String
deriving ToJson, FromJson

/-- Render a given string as Markdown.
LaTeX is supported with MathJax:
use `$...$` for inline math,
and `$$...$$` for displayed math.
Example usage:
```lean
<MarkdownDisplay contents={"$a + b = c$"} />
``` -/
@[widget_module]
def MarkdownDisplay : Component MarkdownDisplay.Props where
javascript := "
import { Markdown } from '@leanprover/infoview'
import * as React from 'react'
export default (props) => React.createElement(Markdown, props)
"

end ProofWidgets

/-- Construct a structured message from a ProofWidgets component.
Expand Down
8 changes: 8 additions & 0 deletions ProofWidgets/Demos/Jsx.lean
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,14 @@ def htmlLetters : Array ProofWidgets.Html := #[
def x := <b>You can use {...htmlLetters} in Lean {.text s!"{1 + 3}"}! <hr/> </b>
#html x

-- Use `MarkdownDisplay` to render Markdown
open ProofWidgets in
#html <MarkdownDisplay contents={"
## Hello, Markdown
We have **bold text**, _italic text_, `example : True := by trivial`,
and $3×19 = \\int\\limits_0^{57}1~dx$.
"} />

-- HTML trees can also be produced by metaprograms
open ProofWidgets Lean Elab in
#html (do
Expand Down

0 comments on commit 20c4298

Please sign in to comment.