feat(ask): syntax-highlight answer code blocks and linkify citations - #4
Merged
Conversation
Answers (and explanations — the renderer is shared) previously pushed fenced code through iced's markdown widget, which renders it as plain monospace: no colors at all. And path:line citations were inert code chips you had to retype into the finder. - richmd: fenced blocks become their own Segment::Code (mermaid keeps its diagram path); prepare_segments highlights them with clew's own tree-sitter pipeline (lang_for_fence maps the common fence tags and aliases), so answer code gets the exact palette of the editor. The block renders on the editor background and scrolls horizontally instead of wrapping. - richmd::linkify_citations: inline-code citations (path:line, path:a-b ranges, bare paths, and unique basenames like theme.rs) become clew: links when they resolve to a real project file — type names and non-files stay code chips. OpenLink handles the clew: scheme by jumping to that file and line in the editor. - Fence contents are never math-scanned or linkified.
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.
Two UX gaps in Ask answers (and Explain views — the renderer is shared):
Syntax highlighting for code blocks
Fenced code went through iced's markdown widget, which renders it as flat monospace (the iced
highlighterfeature is deliberately off — its themes don't match). Fenced blocks are now their own segment, highlighted with clew's own tree-sitter pipeline at prepare time: answer code gets the exact same palette as the editor, on the editor background, scrolling horizontally instead of wrapping.lang_for_fencemaps the common fence tags and aliases (rust/rs,py,ts,golang, …); unknown languages fall back to plain lines. Mermaid fences keep their existing diagram path.Clickable citations
path:linecitations were inert code chips. They now become links (clew:scheme) that jump straight to that file and line in the editor — exactly what the panel's own tagline promises. Resolution is conservative so prose code chips stay chips:src/app/update.rs:62), with:a-branges collapsing to their starttheme.rs:37)Vec<String>) are left alone; fenced blocks are never touchedTested
codeview.rs:668where the blame line shows this morning's fix).