Add Markdown syntax highlighting in the editor#13034
Conversation
fe51a2d to
7fbbf20
Compare
Register Markdown as a supported editor language: enable arborium's lang-markdown grammar and ship a Warp-authored highlights.scm, since arborium's upstream query uses capture names Warp's color mapping does not recognize. load_language now prefers a bundled per-language highlights query, falling back to arborium's bundled one. Covers block-level constructs (headings, code fences, lists, blockquotes, pipe tables, link reference definitions, front matter, HTML blocks). Inline emphasis and per-language highlighting inside code fences require the Markdown inline grammar plus tree-sitter injections, and are left as future work. Also syncs ProgrammingLanguage::to_extension so ```markdown fences in agent output highlight through the same path. Adds unit tests and manual-test fixtures under specs/warpdotdevgh-9042/.
7fbbf20 to
e418934
Compare
Add a tree-sitter injection pass to the editor's highlighter so a fenced code block is highlighted in the language named by its fence (a `rust` fence colors as Rust, `python` as Python, etc.) instead of as one flat color. - languages: give `Language` an `injections_query`, loaded from arborium's Markdown injection query; stop coloring `code_fence_content` in the bundled `highlights.scm` so injected tokens show with default-colored gaps. - syntax_tree: `injected_highlights` runs the injection query, resolves each fence's language via `language_by_name`, parses the body with that grammar, and merges the resulting colors over the base Markdown highlights. The query is scoped to the viewport, and node text is read via `node.utf8_text` (tree-sitter's byte offsets) to avoid the buffer's offset-base mismatch. Adds unit tests for per-language highlighting, unknown / no-language fences, and multi-byte offset safety, plus a long-code-block fixture under specs/warpdotdevgh-9042/.
|
I'm starting a first review of this pull request. You can view the conversation on Warp. I reviewed this pull request and requested human review from: Comment Powered by Oz |
|
/oz-review |
|
I'm re-reviewing this pull request in response to a review request. You can view the conversation on Warp. I completed the review and no human review was requested for this pull request. Comment Powered by Oz |
There was a problem hiding this comment.
Overview
This PR adds Markdown as a supported syntax-highlighted editor language, including grammar registration, a bundled Markdown highlight query, fenced-code injection highlighting, and unit/fixture coverage. Screenshots and a recording are included for the user-facing behavior, and no approved spec context was provided for implementation-drift checks.
Concerns
- One non-blocking source comment still says fenced-code injections are unsupported even though this PR implements them.
Verdict
Found: 0 critical, 0 important, 1 suggestions
Approve with nits
Comment /oz-review on this pull request to retrigger a review (up to 3 times on the same pull request).
Powered by Oz
There was a problem hiding this comment.
Overview
This PR adds Markdown as a supported editor language, registers .md/.markdown handling, adds a custom Markdown highlight query, and introduces injected highlighting for fenced code blocks.
Concerns
- Injected fenced-code highlighting currently reparses and recolors the full fenced block whenever any part of it intersects the viewport, so scrolling through a large Markdown code fence can do large synchronous work on each viewport cache miss.
Verdict
Found: 0 critical, 1 important, 0 suggestions
Request changes
Comment /oz-review on this pull request to retrigger a review (up to 3 times on the same pull request).
Powered by Oz
Injection highlights were recomputed for every viewport, so scrolling a fenced code block re-parsed the visible fences on each cache miss. Move the injection pass out of the per-range loop and cache its whole-document result keyed by buffer version + language, reused across viewport scrolls and invalidated when the tree is reparsed or the color map changes. Also split InjectionCache into an entry + InjectionCacheKey to mirror HighlightCache/HighlightCacheKey, and rename the key's language field so its name matches its Language type (addresses review comments).
|
/oz-review |
|
I'm re-reviewing this pull request in response to a review request. You can view the conversation on Warp. I reviewed this pull request and requested human review from: Comment Powered by Oz |
Oz no longer requests changes for this pull request after the latest automated review.
There was a problem hiding this comment.
Overview
Adds Markdown as a supported editor language, including a Warp-authored Markdown highlight query and an injection pass that highlights fenced code blocks using their embedded language. The PR also updates language alias handling and includes unit coverage plus manual fixtures/screenshots for the user-facing behavior.
Concerns
- No blocking correctness, security, or spec-alignment concerns found in the changed diff. The PR includes screenshots/video links for the user-facing highlighting behavior.
Verdict
Found: 0 critical, 0 important, 0 suggestions
Approve
Comment /oz-review on this pull request to retrigger a review (up to 3 times on the same pull request).
Powered by Oz
The grammar tags only the first `>` of a block quote as a block_quote_marker; each continuation line's `>` is a block_continuation, so multi-line quotes left every marker after the first uncolored. Capture block_continuation as well. (Non-quote block_continuations are whitespace, so coloring them is invisible.)
kevinyang372
left a comment
There was a problem hiding this comment.
Good progress here! Have a few feedback on this
| let highlight_query_str = get_arborium_highlight_query(lang)?; | ||
| let highlight_query = Query::new(&grammar, highlight_query_str) | ||
| .expect("arborium highlight query should be valid"); | ||
| // Prefer a Warp-authored highlight query bundled alongside the grammar, falling back to |
There was a problem hiding this comment.
See comments above, I don't think we need to do this
What are the capture names that we don't recognize? We should consider supporting these capture names rather than rewriting a query from scratch
There was a problem hiding this comment.
The reason I didn't touch convert_capture_name_to_color(...) is because the markdown highlight queries are a different structure. It's your call but the root of the markdown queries are: @text.<keyword> and @punctuation.<keyword> where the existing languages supported by warp use @keyword, @function, etc. The only query that worked out of the box was @string.escape.
Markdown highlights in arborium: https://github.com/bearcove/arborium/blob/c2121b480bd7a8ab537d1f2e10433614405b3a54/langs/group-willow/markdown/def/queries/highlights.scm
Your call, let me know.
My opinion is this a non standard case out of ~30 cases. If it becomes standard it can be refactored into the core function but until then a separate file is satisfactory and doesn't muddy the core logic.
Reverts the tree-sitter injection feature (0f222b0) and its per-version cache (2412847) so this PR is scoped to block-level Markdown highlighting. Per review, language injection — with its performance/caching and multi-language considerations — belongs in its own PR. Reverting the cache commit also restores HighlightCacheKey's original `language_id` field, undoing the out-of-scope rename. Block-level highlighting and the blockquote continuation fix are retained.
Description
Adds Markdown to the languages the editor syntax-highlights. Opening a
.md/.markdownfile in Warp's code editor (Raw view) now highlights block-level structure instead of rendering as plain text.What's supported
Block-level Markdown constructs:
#–######) and setext-*+), ordered (1.3)), and task markers ([x]/[ ])[label]: url "title"What's not supported yet
Everything inline (styling within a line of text):
**bold**,*italic*,~~strikethrough~~`inline code`[title](url), autolinks<url>, reference uses[text][label]Why not yet: these are all inline constructs, which the block grammar collapses into one opaque node. Highlighting them needs the separate Markdown inline grammar, which arborium does not yet package upstream. Tracked as follow-up.
Implementation
lang-markdowngrammar and registermarkdownin thelanguagescrate (.md/.markdownextensions,mdalias).crates/languages/grammars/markdown/highlights.scm. arborium's bundled Markdown query uses nvim-style capture names (text.title,punctuation.special, …) that Warp's color mapping doesn't recognize, soload_languagenow prefers a bundled per-language query and falls back to arborium's for every other language.ProgrammingLanguage::to_extensionso fenced```markdownblocks in agent output highlight through the same path.Linked Issue
Closes #9042.
ready-to-specorready-to-implement.Testing
I have manually tested my changes locally with
./script/runUnit:
crates/languages—markdown_extensions_resolve_to_markdownandall_supported_languages_load_successfully(compiles the bundledhighlights.scm);app—to_extensioncovers themarkdown/mdfence aliases. Full presubmit (clippy + nextest) is green apart from pre-existing environment-only SSH integration tests.Manual: verified every highlight rule against the fixtures in
specs/gh-9042/(01–04) in the editor's Raw view.Screenshots / Videos
Captured in the editor's Raw view (dark theme); each fixture lives in
specs/gh-9042/.1. Headings & front matter —
01-headings.md2. Lists, tasks, quotes & rules —
02-lists-quotes-rules.md3. Code blocks —
03-code.md4. Links, table, HTML & inline limitation —
04-links-table-html-inline.mdAgent Mode
CHANGELOG-IMPROVEMENT: Markdown files now have syntax highlighting in the editor.