feat: preserve and render widget messages in HTML output#817
Draft
alok wants to merge 3 commits intoleanprover:mainfrom
Draft
feat: preserve and render widget messages in HTML output#817alok wants to merge 3 commits intoleanprover:mainfrom
alok wants to merge 3 commits intoleanprover:mainfrom
Conversation
Adds a new `Block.figure` block extension and `:::figure` directive
to the Manual genre, enabling authors to embed images with optional
captions in Verso documents.
Directive syntax:
:::figure "path/to/image.png" (alt := "description")
Optional caption text rendered in <figcaption>.
:::
- HTML output: <figure class="verso-figure"><img/><figcaption/></figure>
- LaTeX output: figure environment with \includegraphics + \caption{}
- Adds \usepackage{graphicx} to the LaTeX preamble automatically
- Responsive CSS: max-width 100%, centered, styled figcaption
- alt argument optional (defaults to ""), src is positional
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This reverts commit 1018d0c.
Preserve and render Lean user widget messages (MessageData.ofWidget) in Verso HTML output instead of discarding them. SubVerso changes (alok/subverso@feature/widget-messages-rc6): - Add `widget` constructor to `MessageContents` storing the widget module's `javascriptHash`, serialized `props` JSON, and `alt` text - Change `onWidget` handler to evaluate widget props with an empty RPC object store and preserve them (instead of discarding) Verso changes: - HTML: render `.widget` as `<span class="widget-message">` with `data-widget-hash` and `data-widget-props` attributes, falling back to the alt text content. This enables future JS hydration with @leanprover/infoview in shim mode. - TeX: render `.widget` as its alt text (widgets are interactive) - Update all pattern matches for the new `MessageContents.widget` Remaining work for full interactive widget rendering: - Bundle React and @leanprover/infoview JS in generated HTML - Implement infoview "shim mode" (server calls fail gracefully) - JS to discover `[data-widget-hash]` elements and hydrate them Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Addresses #311 — preserves Lean user widget messages (
MessageData.ofWidget) through the SubVerso → Verso pipeline instead of discarding them.Before:
(onWidget := fun _wi alt => convert alt)— widget instances thrown away, only alt text kept.After: Widget
javascriptHash+ serializedpropsJSON flow throughMessageContents.widgetand are emitted as data attributes in HTML output.Changes
SubVerso (alok/subverso@feature/widget-messages-rc6)
| widget (javascriptHash : Nat) (props : String) (alt : MessageContents expr)constructor toHighlighted.MessageContentsonWidgethandler inCode.leanto evaluate widget props with an emptyRpcObjectStoreand store them (serializable widgets produce valid JSON; RPC-dependent widgets degrade to alt text)Exporttypes,Quoteinstance,toString,startAt,stopAtpattern matchesVerso (this PR)
MessageContents.toHtml): Render.widgetas<span class="widget-message" data-widget-hash="..." data-widget-props="...">with alt text as visible content.widgetas its alt text (widgets are interactive-only).widgetcase tofindTrace?How it works
When Lean code in a Verso document emits a widget message (e.g., a LeanPlot chart or ProofWidgets visualization):
WidgetInstanceduring highlighting, evaluates its props to JSON, and stores(hash, props, alt)inMessageContents.widgetdata-*attributes[data-widget-hash]elements, fetch the widget module source by hash, and hydrate them with ReactRemaining work for full interactive rendering
Per the discussion in #311, complete widget rendering requires:
@leanprover/infoviewin generated HTML pages[data-widget-hash]elements, dynamically import widget modules by hash, and render React components with the serialized propsTest plan
lake buildpasses for SubVerso (56/56 jobs)lake buildpasses for Verso (470/470 jobs)#evaland inspecting the HTML output fordata-widget-hashattributes🤖 Generated with Claude Code