Task 19: rich_text widget from the Markdown AST (#19) #41

Manually merged
charles merged 0 commits from task/19-ui-rich-text into foundation 2026-11-11 18:28:16 +00:00
Owner

Stacked on: task/16-ui-theme-fonts-icons

What this builds

fluxer_ui::widgets::rich_text:

  • parse_message(content) -> Vec<Node>: the fork's fluxer_markdown_parser with ParserFlags::ALL minus headings, lists, tables and alerts, EmojiContext::default(). A parser error returns the content as one literal text node.
  • blocks(nodes, ctx) -> Vec<Block> and spans(nodes, ctx) -> Vec<SpanModel>: the span model (text, bold, italic, strike, underline, mono, color, background, link, spoiler, hidden). Paragraphs, code blocks and block quotes are blocks; spans is the flat view of them.
  • rich_text(nodes, ctx) -> Element<Message, Theme>: iced rich text spans for paragraphs, a mono block with language label for code blocks, a 4 px bar for block quotes. Strong is weight 600, mentions are pills (role mentions take the role colour), spoilers are hidden until clicked, links use text_link, <t:...> timestamps are formatted in the offset the caller passes, custom emoji show as :name:, any other node shows its plain text via render_ast_to_plaintext.
  • RenderCtx { resolve_user, resolve_channel, resolve_role, resolve_role_color, revealed_spoilers, utc_offset, now_unix }.

How it was tested

crates/fluxer-ui/tests/rich_text.rs, 21 tests on the span model, written first and seen failing: the five the plan names (bold_italic_nest, inline_code_is_mono, mention_user_resolves_name, link_has_url, unsupported_node_falls_back_to_plaintext) plus spoilers, masked links, code blocks, block quotes, every timestamp style, role/everyone/here mentions, unparseable mention ids, and hostile input (must not panic, including building the widget). cargo xtask ci is green locally. The widget has not been looked at on screen: nothing on foundation can host it yet (no app shell), so there are no side-by-side screenshots; that falls to Task 20 / Task 24.

Deviations from the plan

  • Git dependency over anonymous HTTPS, no deploy key. charles/fluxer is public, so the dependency is https://git.forked.io/charles/fluxer.git at rev ba98441b instead of the SSH URL; no FORK_DEPLOY_KEY secret and no CI change are needed. Not verified on the runners from here: they must be able to reach git.forked.io over HTTPS. Cost to know about: cargo clones the whole fork (about 1.2 GB, close to 3 minutes locally), on every Linux run since that container is not cached (#27). If that is too slow or the runner cannot reach the host, the plan's fallback (vendoring into third_party/) applies.
  • Licence. The parser is AGPL-3.0-or-later; deny.toml gets a per-crate exception. Linking it makes the client binary AGPL.
  • Returns Element<rich_text::Message, Theme>, not Element<UiMessage>. UiMessage is Task 17's and is not on foundation; the caller maps Message::{LinkClicked(String), SpoilerToggled(usize)}.
  • Effect::OpenUrl is not added. fluxer-core is still empty on foundation (Task 8 unmerged). Tracked in #40 together with the UiMessage mapping and the spoiler state.
  • Spoiler state lives with the caller (RenderCtx::revealed_spoilers, indexed per spoiler in document order), since the UI-local state struct is Task 17's.
  • Colours follow the web app's CSS rather than the plan's token names where they differ: inline code uses --bg-code / --text-code (not background_secondary_alt), mentions use --markup-mention-text / --markup-mention-fill (not brand_primary), per Markup.module.css.
  • Extra RenderCtx fields beyond the three the plan lists: resolve_role, revealed_spoilers, utc_offset, now_unix. spans takes the ctx as second argument.
  • Timestamps use en-US, 12-hour formats (what the web app's Intl formatter gives for en-US); the client has no locale setting yet.
  • New files outside the task's list: crates/fluxer-ui/src/widgets/mod.rs (Task 17 creates it too; add/add conflict is one line), pub mod widgets; in lib.rs, deny.toml, Cargo.lock, the crate README. fluxer-ui now depends on fluxer-proto (Snowflake) and the workspace's time.

Closes #19

🤖 Generated with Claude Code

Stacked on: task/16-ui-theme-fonts-icons ## What this builds `fluxer_ui::widgets::rich_text`: - `parse_message(content) -> Vec<Node>`: the fork's `fluxer_markdown_parser` with `ParserFlags::ALL` minus headings, lists, tables and alerts, `EmojiContext::default()`. A parser error returns the content as one literal text node. - `blocks(nodes, ctx) -> Vec<Block>` and `spans(nodes, ctx) -> Vec<SpanModel>`: the span model (`text, bold, italic, strike, underline, mono, color, background, link, spoiler, hidden`). Paragraphs, code blocks and block quotes are blocks; `spans` is the flat view of them. - `rich_text(nodes, ctx) -> Element<Message, Theme>`: iced rich text spans for paragraphs, a mono block with language label for code blocks, a 4 px bar for block quotes. Strong is weight 600, mentions are pills (role mentions take the role colour), spoilers are hidden until clicked, links use `text_link`, `<t:...>` timestamps are formatted in the offset the caller passes, custom emoji show as `:name:`, any other node shows its plain text via `render_ast_to_plaintext`. - `RenderCtx { resolve_user, resolve_channel, resolve_role, resolve_role_color, revealed_spoilers, utc_offset, now_unix }`. ## How it was tested `crates/fluxer-ui/tests/rich_text.rs`, 21 tests on the span model, written first and seen failing: the five the plan names (`bold_italic_nest`, `inline_code_is_mono`, `mention_user_resolves_name`, `link_has_url`, `unsupported_node_falls_back_to_plaintext`) plus spoilers, masked links, code blocks, block quotes, every timestamp style, role/everyone/here mentions, unparseable mention ids, and hostile input (must not panic, including building the widget). `cargo xtask ci` is green locally. The widget has not been looked at on screen: nothing on `foundation` can host it yet (no app shell), so there are no side-by-side screenshots; that falls to Task 20 / Task 24. ## Deviations from the plan - **Git dependency over anonymous HTTPS, no deploy key.** `charles/fluxer` is public, so the dependency is `https://git.forked.io/charles/fluxer.git` at rev `ba98441b` instead of the SSH URL; no `FORK_DEPLOY_KEY` secret and no CI change are needed. Not verified on the runners from here: they must be able to reach `git.forked.io` over HTTPS. Cost to know about: cargo clones the whole fork (about 1.2 GB, close to 3 minutes locally), on every Linux run since that container is not cached (#27). If that is too slow or the runner cannot reach the host, the plan's fallback (vendoring into `third_party/`) applies. - **Licence.** The parser is AGPL-3.0-or-later; `deny.toml` gets a per-crate exception. Linking it makes the client binary AGPL. - **Returns `Element<rich_text::Message, Theme>`, not `Element<UiMessage>`.** `UiMessage` is Task 17's and is not on `foundation`; the caller maps `Message::{LinkClicked(String), SpoilerToggled(usize)}`. - **`Effect::OpenUrl` is not added.** `fluxer-core` is still empty on `foundation` (Task 8 unmerged). Tracked in #40 together with the `UiMessage` mapping and the spoiler state. - **Spoiler state lives with the caller** (`RenderCtx::revealed_spoilers`, indexed per spoiler in document order), since the UI-local state struct is Task 17's. - **Colours follow the web app's CSS rather than the plan's token names** where they differ: inline code uses `--bg-code` / `--text-code` (not `background_secondary_alt`), mentions use `--markup-mention-text` / `--markup-mention-fill` (not `brand_primary`), per `Markup.module.css`. - **Extra `RenderCtx` fields** beyond the three the plan lists: `resolve_role`, `revealed_spoilers`, `utc_offset`, `now_unix`. `spans` takes the ctx as second argument. - **Timestamps use en-US, 12-hour formats** (what the web app's `Intl` formatter gives for en-US); the client has no locale setting yet. - New files outside the task's list: `crates/fluxer-ui/src/widgets/mod.rs` (Task 17 creates it too; add/add conflict is one line), `pub mod widgets;` in `lib.rs`, `deny.toml`, `Cargo.lock`, the crate README. `fluxer-ui` now depends on `fluxer-proto` (`Snowflake`) and the workspace's `time`. Closes #19 🤖 Generated with [Claude Code](https://claude.com/claude-code)
feat(ui): generated theme tokens, fonts and icons
All checks were successful
ci / Windows (x64) (push) Successful in 22s
ci / Windows (x64) (pull_request) Successful in 15s
ci / Linux (x86_64) (push) Successful in 1m22s
ci / Linux (x86_64) (pull_request) Successful in 1m23s
64430a109d
- xtask gen-theme --fork <path>: parses the Electron app's colour system,
  globals and message-layout CSS into crates/fluxer-ui/src/theme/tokens.rs
  (hsl/hsla/rgb/hex, saturation-factor calc, var() fallbacks, color-mix in
  srgb and oklab; rem to px).
- fluxer-ui::theme: tokens (DARK), palette::Theme with iced's Base and
  widget catalogs, fonts (Fluxer Sans/Mono as TTF) and icons (Phosphor SVGs).
- Adds iced 0.14 to the workspace; deny.toml allows BSL-1.0 and CC0-1.0 and
  ignores three unmaintained-crate advisories that iced pulls in.

Refs #16

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Merge origin/foundation into task/16-ui-theme-fonts-icons
All checks were successful
ci / Windows (x64) (push) Successful in 1m32s
ci / Windows (x64) (pull_request) Successful in 38s
ci / Linux (x86_64) (push) Successful in 1m28s
ci / Linux (x86_64) (pull_request) Successful in 1m34s
897ebaae93
Conflicts in xtask (both sides implemented dispatch stubs: gen-theme here,
vendor-spec/spec-check on foundation) and Cargo.lock resolved as the union.

Refs #16

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Merge origin/foundation into task/16-ui-theme-fonts-icons
All checks were successful
ci / Windows (x64) (push) Successful in 44s
ci / Linux (x86_64) (push) Successful in 1m41s
ci / Windows (x64) (pull_request) Successful in 52s
ci / Linux (x86_64) (pull_request) Successful in 1m31s
301b889ef7
Mechanical conflicts: both sides added workspace dependencies (iced, futures-util)
and Cargo.lock entries.

Refs #16

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
fluxer_markdown_parser is pinned to the fork's main (ba98441b) over the anonymous
HTTPS URL: the fork is public, so the CI runners need no deploy key. cargo-deny
gets the git source and a per-crate AGPL-3.0-or-later licence exception.

Refs #19

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Refs #19

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
feat(ui): rich text from the native Markdown parser
All checks were successful
ci / Linux (x86_64) (push) Successful in 4m44s
ci / Windows (x64) (push) Successful in 5m45s
ci / Windows (x64) (pull_request) Successful in 46s
ci / Linux (x86_64) (pull_request) Successful in 4m29s
72276377ff
parse_message runs the fork's parser with the message flags; blocks/spans turn the
AST into a span model (tested instead of pixels); rich_text draws it with iced rich
text spans, code blocks and block quotes, and emits LinkClicked / SpoilerToggled.

Refs #19

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Author
Owner

Independent review: Task 19 (rich_text), head 7227637

Scope: git diff 301b889..origin/task/19-ui-rich-text (10 files, +1268). Read cold; the implementer's notes were verified, not trusted.

Verdict: APPROVED. 0 blocking, 5 minor. Local cargo xtask ci: green (fmt, clippy -D warnings, deny, tests; 21/21 in tests/rich_text.rs; screenshot step skipped locally because FLUXER_SCREENSHOT_TESTS is not 1). Remote runners were not checked by me.

What I checked

  1. Plan tests: bold_italic_nest, inline_code_is_mono, mention_user_resolves_name, link_has_url, unsupported_node_falls_back_to_plaintext (builds a Table node by hand) all exist and assert what the plan says. Test-first commit order is there (6f059d0 before 7227637).
  2. Interfaces: parse_message(&str) -> Vec<Node> exact; flags are ALL & !(HEADINGS|LISTS|TABLES|ALERTS), EmojiContext::default(). Inline code radius 3 px, quote bar 4 px, custom emoji :name:, unknown nodes via render_ast_to_plaintext. Deviations are listed under minor 1.
  3. Invariants: no I/O in fluxer-ui (the UTC offset and "now" are passed in, nothing is read from the OS); fluxer-core untouched; no secrets in code or tests. Panic safety: besides the branch's own hostile_input_never_panics, I ran a throwaway probe (not committed): 20 000 pseudo-random Markdown strings through parse_message / spans / rich_text, plus 2 000-deep > > > … quotes. No panic. The parser flattens nested quotes to depth 1 and bounds inline depth at 10, so the unguarded recursion in walk / tidy / view_blocks is bounded for parser output.
  4. Review Focus: none of the five items belongs to this task.
  5. Dependency: charles/fluxer answers anonymously (API 200, git ls-remote with no credential helper returns ba98441b…), so the HTTPS pin needs no deploy key. Longest path in the fork at that rev is 124 characters, so the Windows checkout stays under MAX_PATH. The parser only produces http(s):, fluxer:, mailto:, tel: and sms: link URLs; javascript: and file: stay literal text.

Findings

  • minor 1, interface deviations Task 20 must adapt to (widgets/rich_text/mod.rs): rich_text returns Element<'a, rich_text::Message, Theme>, not Element<'a, UiMessage>; RenderCtx has four fields beyond the plan's three (resolve_role, revealed_spoilers, utc_offset, now_unix); spans takes the ctx as a second argument. Unavoidable today (UiMessage and Local are Task 17's, not on foundation) and tracked in #40, but Task 20's implementer has to read the merged code, not the plan block. Effect::OpenUrl is not added (core is a 3-line stub on this base); also #40.
  • minor 2, link opening needs a scheme allowlist at the call site (#40): Message::LinkClicked(String) carries the parser's URL as is, including fluxer:, mailto:, tel:, sms:. Whoever implements Effect::OpenUrl should decide which schemes go to the system opener; worth adding to #40.
  • minor 3, the git dependency is unverified on the runners and heavy: cargo clones the whole fork (about 16 000 files) on every uncached run, and the runners must reach git.forked.io over HTTPS. If either bites, the plan's vendoring fallback applies. Integrator to confirm on both runners.
  • minor 4, licence, for Charles: deny.toml gains an AGPL-3.0-or-later exception for fluxer_markdown_parser; linking it makes the client binary AGPL. The workspace declares no licence of its own yet. Not a code defect, but it is a decision that should be acknowledged before merge.
  • minor 5, not seen on screen, no screenshot test: spec §5.2 asks for a screenshot test per widget; nothing on foundation can host the widget, so pixels (pill padding, the Length::Fill quote bar inside a Shrink row, transparent text for hidden spoilers) are untested until Task 20 / 24. paragraph also reads tokens::DARK directly rather than the active theme, which is fine while dark is the only theme.

Process: commits carry Refs #19 and the co-author trailer; PR title and body follow the contract (Closes #19, Stacked on:), follow-up #40 is open and labelled.

## Independent review: Task 19 (`rich_text`), head `7227637` Scope: `git diff 301b889..origin/task/19-ui-rich-text` (10 files, +1268). Read cold; the implementer's notes were verified, not trusted. **Verdict: APPROVED. 0 blocking, 5 minor. Local `cargo xtask ci`: green** (fmt, clippy `-D warnings`, deny, tests; 21/21 in `tests/rich_text.rs`; screenshot step skipped locally because `FLUXER_SCREENSHOT_TESTS` is not 1). Remote runners were not checked by me. ### What I checked 1. **Plan tests**: `bold_italic_nest`, `inline_code_is_mono`, `mention_user_resolves_name`, `link_has_url`, `unsupported_node_falls_back_to_plaintext` (builds a `Table` node by hand) all exist and assert what the plan says. Test-first commit order is there (`6f059d0` before `7227637`). 2. **Interfaces**: `parse_message(&str) -> Vec<Node>` exact; flags are `ALL & !(HEADINGS|LISTS|TABLES|ALERTS)`, `EmojiContext::default()`. Inline code radius 3 px, quote bar 4 px, custom emoji `:name:`, unknown nodes via `render_ast_to_plaintext`. Deviations are listed under minor 1. 3. **Invariants**: no I/O in `fluxer-ui` (the UTC offset and "now" are passed in, nothing is read from the OS); `fluxer-core` untouched; no secrets in code or tests. Panic safety: besides the branch's own `hostile_input_never_panics`, I ran a throwaway probe (not committed): 20 000 pseudo-random Markdown strings through `parse_message` / `spans` / `rich_text`, plus 2 000-deep `> > > …` quotes. No panic. The parser flattens nested quotes to depth 1 and bounds inline depth at 10, so the unguarded recursion in `walk` / `tidy` / `view_blocks` is bounded for parser output. 4. **Review Focus**: none of the five items belongs to this task. 5. **Dependency**: `charles/fluxer` answers anonymously (API 200, `git ls-remote` with no credential helper returns `ba98441b…`), so the HTTPS pin needs no deploy key. Longest path in the fork at that rev is 124 characters, so the Windows checkout stays under MAX_PATH. The parser only produces `http(s):`, `fluxer:`, `mailto:`, `tel:` and `sms:` link URLs; `javascript:` and `file:` stay literal text. ### Findings - **minor 1, interface deviations Task 20 must adapt to** (`widgets/rich_text/mod.rs`): `rich_text` returns `Element<'a, rich_text::Message, Theme>`, not `Element<'a, UiMessage>`; `RenderCtx` has four fields beyond the plan's three (`resolve_role`, `revealed_spoilers`, `utc_offset`, `now_unix`); `spans` takes the ctx as a second argument. Unavoidable today (`UiMessage` and `Local` are Task 17's, not on `foundation`) and tracked in #40, but Task 20's implementer has to read the merged code, not the plan block. `Effect::OpenUrl` is not added (core is a 3-line stub on this base); also #40. - **minor 2, link opening needs a scheme allowlist at the call site** (#40): `Message::LinkClicked(String)` carries the parser's URL as is, including `fluxer:`, `mailto:`, `tel:`, `sms:`. Whoever implements `Effect::OpenUrl` should decide which schemes go to the system opener; worth adding to #40. - **minor 3, the git dependency is unverified on the runners and heavy**: cargo clones the whole fork (about 16 000 files) on every uncached run, and the runners must reach `git.forked.io` over HTTPS. If either bites, the plan's vendoring fallback applies. Integrator to confirm on both runners. - **minor 4, licence, for Charles**: `deny.toml` gains an `AGPL-3.0-or-later` exception for `fluxer_markdown_parser`; linking it makes the client binary AGPL. The workspace declares no licence of its own yet. Not a code defect, but it is a decision that should be acknowledged before merge. - **minor 5, not seen on screen, no screenshot test**: spec §5.2 asks for a screenshot test per widget; nothing on `foundation` can host the widget, so pixels (pill padding, the `Length::Fill` quote bar inside a `Shrink` row, transparent text for hidden spoilers) are untested until Task 20 / 24. `paragraph` also reads `tokens::DARK` directly rather than the active theme, which is fine while dark is the only theme. Process: commits carry `Refs #19` and the co-author trailer; PR title and body follow the contract (`Closes #19`, `Stacked on:`), follow-up #40 is open and labelled.
charles manually merged commit 24e7c9d137 into foundation 2026-11-11 18:28:16 +00:00
Sign in to join this conversation.
No description provided.