feat: RichBlock enum + RichMessageParser HTML parser (#29, #36) #131

Closed
charles wants to merge 4 commits from feat/29-36-rich-parser into main
Owner

Summary

  • Adds RichBlock enum covering all 13 block types: Chart, Quiz, PollRich, CodeRun, Card, Carousel, Timeline, TableSort, Accordion, Progress, Math, Mermaid, Canvas (crates/fractal-rich/src/block.rs)
  • Adds RichMessageParser::parse(html) -> Vec<MessageFragment> with Html(String) / Rich { block, fallback } variants, plus RenderLevel (full / static / text) (crates/fractal-rich/src/parser.rs)
  • Fallback to MessageFragment::Html on unknown data-fx-type or invalid data-fx-config JSON
  • Adds scraper = "0.20", serde, serde_json to fractal-rich/Cargo.toml
  • Exposes all public types via lib.rs

Test plan

  • cargo test -p fractal-rich — all unit tests pass (block deserialization, unknown type, invalid JSON, text render level, plain HTML passthrough)
  • Verify fallback: feed a <div data-fx-type="unknown-widget"> and confirm MessageFragment::Html is returned
  • Verify RenderLevel::Text strips all rich blocks and returns plain text

Closes #29, closes #36

## Summary - Adds `RichBlock` enum covering all 13 block types: Chart, Quiz, PollRich, CodeRun, Card, Carousel, Timeline, TableSort, Accordion, Progress, Math, Mermaid, Canvas (`crates/fractal-rich/src/block.rs`) - Adds `RichMessageParser::parse(html) -> Vec<MessageFragment>` with `Html(String)` / `Rich { block, fallback }` variants, plus `RenderLevel` (`full` / `static` / `text`) (`crates/fractal-rich/src/parser.rs`) - Fallback to `MessageFragment::Html` on unknown `data-fx-type` or invalid `data-fx-config` JSON - Adds `scraper = "0.20"`, `serde`, `serde_json` to `fractal-rich/Cargo.toml` - Exposes all public types via `lib.rs` ## Test plan - [ ] `cargo test -p fractal-rich` — all unit tests pass (block deserialization, unknown type, invalid JSON, text render level, plain HTML passthrough) - [ ] Verify fallback: feed a `<div data-fx-type="unknown-widget">` and confirm `MessageFragment::Html` is returned - [ ] Verify `RenderLevel::Text` strips all rich blocks and returns plain text Closes #29, closes #36
charles closed this pull request 2026-04-06 02:21:49 +00:00
Some checks are pending
CI / cargo check (pull_request) Has been cancelled
CI / cargo test (pull_request) Has been cancelled
CI / clippy + rustfmt (pull_request) Has been cancelled
qa
Required

Pull request closed

Sign in to join this conversation.
No description provided.