Skip to content

Instantly share code, notes, and snippets.

@Vtec234
Created April 26, 2023 21:14
Show Gist options
  • Save Vtec234/7ecf31b2a67341558692e60a2f870853 to your computer and use it in GitHub Desktop.
Save Vtec234/7ecf31b2a67341558692e60a2f870853 to your computer and use it in GitHub Desktop.
import ProofWidgets.Data.Html
import ProofWidgets.Component.HtmlDisplay
namespace ProofWidgets
syntax (name := htmlIoCmd) "#html_io " term : command
open Lean Elab Server
unsafe def evalHtmlIoUnsafe (stx : Term) : TermElabM (IO Html) := do
let htmlT := .app (mkConst ``IO) (mkConst ``Html)
Term.evalTerm (IO Html) htmlT stx
@[implemented_by evalHtmlIoUnsafe]
opaque evalHtmlIo : Term → TermElabM (IO Html)
open Command Json in
@[command_elab htmlIoCmd]
def elabHtmlIoCmd : CommandElab := fun
| stx@`(#html_io $t:term) =>
runTermElabM fun _ => do
let htX ← evalHtmlIo t
let ht ← htX
savePanelWidgetInfo stx ``HtmlDisplayPanel do
return json% { html: $(← rpcEncode ht) }
| stx => throwError "Unexpected syntax {stx}."
end ProofWidgets
open ProofWidgets
open scoped ProofWidgets.Jsx
#html_io do
return Html.ofTHtml <b>Test <i>italic</i></b>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment