Markdown: math-ish content + collapsible tool-call blocks #14
Labels
No labels
Compat/Breaking
Kind/Bug
Kind/Documentation
Kind/Enhancement
Kind/Feature
Kind/Security
Kind/Testing
Priority
Critical
Priority
High
Priority
Low
Priority
Medium
Reviewed
Confirmed
Reviewed
Duplicate
Reviewed
Invalid
Reviewed
Won't Fix
Status
Abandoned
Status
Blocked
Status
Need More Info
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
lyssieth/sermones#14
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Follow-up to #6. Two checklist items on the chat-view issue were deferred to keep that shippable scope tight. Both are still open; the notes below are re-grounded against the tree as of
dd1a00f.crates/sermones-core/src/markdown/) covers prose, tables, footnotes, strikethrough, task lists, definition lists, and code blocks with arborium highlight classes. No math, on two counts:Options::ENABLE_MATHis not in the option set (renderer.rs:167-171), so pulldown-cmark never emits math events; and the two events are explicitly discarded where they would land (Event::InlineMath(_) | Event::DisplayMath(_) => { /* skip */ },renderer.rs:327-333). The renderer is sans-IO and outputs a sanitized HTML fragment, so any math pass must play in that pipeline and survivesanitize_html_fragment.<details class="reasoning">(crates/sermones/src/streaming.rs:188-196,compose_fragment). Tool calls land inMessage::blocksasBlock::ToolCall(...)(crates/sermones-core/src/llm/message.rs:79, assembled bymerge_tool_callat:308) and are then silently dropped from the render: the fragment is built fromBlock::Outputtext plusBlock::Reasoningtext and nothing else (streaming.rs:211-220,output_text_of/reasoning_text_ofat:252-272). So this is not a restyle — nothing reaches the DOM today.The sanitizer is the hard constraint on math
Worth settling before picking a library, because it rules two obvious options out (
crates/sermones-core/src/html_sanitizer.rs, policy indocs/invariants/html-sanitization.md):styleis rejected outright — as an attribute (:918, alongsideon*andxmlns) and as a tag (:896). KaTeX's HTML output is spans carrying inlinestylefor widths, heights, and vertical-align; sanitized, it renders as scrambled glyphs rather than an equation.math/mrow/semantics/annotationinALLOWED_TAGS(:807-875), and thexmlnsattribute is rejected.<details>,<summary>, theopenattribute ondetails, andclasson anything (:823,:859,:951-955). So marker-element approaches survive untouched.Three viable shapes, cheapest first:
<span class="math-inline">…</span>/<div class="math-display">…</div>with the LaTeX source as text;MessageView.svelteruns KaTeX over those nodes after the{@html}injection (:341,:265). Nothing in the sanitizer changes — the marker is class-only, and the untrusted payload stays text until KaTeX itself renders it. Costs a client-side pass on every re-render, and chunks replace the fragment wholesale (see below).docs/invariants/html-sanitization.mdplus tests.stylecarve-out. Rejected unless someone has a strong argument: a generalstyleallowance on model-authored HTML is exactly what the policy exists to prevent.Note KaTeX would be bundled through npm, not the CDN — the app is a local QtWebEngine surface. (
cdn.jsdelivr.neton theimgorigin allowlist at:985is unrelated.)Checklist
$...$and$$...$$, plus / minus\(...\)/\[...\]) — pulldown-cmark'sENABLE_MATHgives$/$$only; the\(...\)forms need a pre-passOptions::ENABLE_MATHadded and the two skip arms atrenderer.rs:327-333given real bodies (plus the inline-level equivalent)sanitize_html_fragment, withdocs/invariants/html-sanitization.mdupdated if the policy movesstreaming.rs:188-220past output + reasoning<details class="tool-call"><summary>{fn}</summary>…</details>, collapsed by default (passes the sanitizer as-is)AssistantMessageView.text— what Copy puts on the clipboard — isBlock::Outputruns only (crates/sermones-core/src/ipc.rs:249-253), so a copyable tool call is a decision about that field, not just about the markup.<details class="reasoning">,streaming.rs:194)MessageView.sveltestyles for both new blocks — next to the existing:global(details.reasoning)rules (MessageView.svelte:517)Streaming interaction (both items)
stream_chunkcarries the whole re-rendered fragment and the frontend replaces it wholesale (frontend/src/lib/conversations.svelte.ts:365-371;{@html assistant.html}atMessageView.svelte:341). Consequences:<details>a user opened mid-stream loses itsopenstate on the next chunk. The reasoning block already lives with this because the engine setsopenwhile streaming and collapses on the terminal (compose_fragment'sopenargument); a tool-call block needs the equivalent decision.Out of scope
RequestMessagecannot even carry atool_call_id(crates/sermones-runtime/src/providers/llama.rs:199-205), andcontext_messagesdrops tool blocks on purpose (crates/sermones-runtime/src/session/mod.rs:541-544).Refs
crates/sermones-core/src/markdown/renderer.rs:167-171,327-333— enabled options; the skipped math eventscrates/sermones-core/src/markdown/html.rs— sans-IO renderer (render_to_html,render_inline_html)crates/sermones-core/src/html_sanitizer.rs:807-875,894-955— tag / attribute policy (docs/invariants/html-sanitization.md)crates/sermones/src/streaming.rs:188-220—compose_fragment, the block → HTML pathcrates/sermones-core/src/llm/message.rs:79,308—Block::ToolCall,merge_tool_callcrates/sermones-core/src/llm/stream_parser/tool_call.rs— tool-call model#6— the chat-view issue, closed without these items