Skip to content

Add Markdown syntax highlighting in the editor#13034

Open
bradleyjames wants to merge 5 commits into
warpdotdev:masterfrom
bradleyjames:brad/GH-9042-markdown-syntax-highlighting
Open

Add Markdown syntax highlighting in the editor#13034
bradleyjames wants to merge 5 commits into
warpdotdev:masterfrom
bradleyjames:brad/GH-9042-markdown-syntax-highlighting

Conversation

@bradleyjames

@bradleyjames bradleyjames commented Jun 25, 2026

Copy link
Copy Markdown
Contributor

Description

Adds Markdown to the languages the editor syntax-highlights. Opening a .md / .markdown file 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:

  • Headings — ATX (#######) and setext
  • Fenced code blocks — fence delimiters, the info-string language, and the code body
  • Indented code blocks
  • Lists — bullets (- * +), ordered (1. 3)), and task markers ([x] / [ ])
  • Blockquotes and thematic breaks
  • Link reference definitions[label]: url "title"
  • Pipe tables — the column separators and delimiter row
  • HTML blocks
  • YAML / TOML front matter

What's not supported yet

Everything inline (styling within a line of text):

  • Emphasis — **bold**, *italic*, ~~strikethrough~~
  • `inline code`
  • In-text links — [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

  • Enable arborium's lang-markdown grammar and register markdown in the languages crate (.md / .markdown extensions, md alias).
  • Ship a Warp-authored 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, so load_language now prefers a bundled per-language query and falls back to arborium's for every other language.
  • Sync ProgrammingLanguage::to_extension so fenced ```markdown blocks in agent output highlight through the same path.

Linked Issue

Closes #9042.

  • The linked issue is labeled ready-to-spec or ready-to-implement.
  • Where appropriate, screenshots or a short video of the implementation are included below.

Testing

  • I have manually tested my changes locally with ./script/run

  • Unit: crates/languagesmarkdown_extensions_resolve_to_markdown and all_supported_languages_load_successfully (compiles the bundled highlights.scm); appto_extension covers the markdown/md fence 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/ (0104) 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 matter01-headings.md

01-headings

2. Lists, tasks, quotes & rules02-lists-quotes-rules.md

02-list-quotes

3. Code blocks03-code.md

03-code

4. Links, table, HTML & inline limitation04-links-table-html-inline.md

04-links-table-html-inline

Agent Mode

  • Warp Agent Mode - This PR was created via Warp's AI Agent Mode

CHANGELOG-IMPROVEMENT: Markdown files now have syntax highlighting in the editor.

@cla-bot cla-bot Bot added the cla-signed label Jun 25, 2026
@github-actions github-actions Bot added the external-contributor Indicates that a PR has been opened by someone outside the Warp team. label Jun 25, 2026
@bradleyjames bradleyjames force-pushed the brad/GH-9042-markdown-syntax-highlighting branch from fe51a2d to 7fbbf20 Compare June 26, 2026 01:06
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/.
@bradleyjames bradleyjames force-pushed the brad/GH-9042-markdown-syntax-highlighting branch from 7fbbf20 to e418934 Compare June 26, 2026 01:18
@bradleyjames bradleyjames marked this pull request as ready for review June 26, 2026 01:47
@bradleyjames bradleyjames marked this pull request as draft June 26, 2026 02:59
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/.
@bradleyjames bradleyjames marked this pull request as ready for review June 28, 2026 01:47
@oz-for-oss

oz-for-oss Bot commented Jun 28, 2026

Copy link
Copy Markdown
Contributor

@bradleyjames

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: @kevinyang372.

Comment /oz-review on this pull request to retrigger a review (up to 3 times on the same pull request).

Powered by Oz

@bradleyjames

Copy link
Copy Markdown
Contributor Author

/oz-review

@oz-for-oss

oz-for-oss Bot commented Jun 28, 2026

Copy link
Copy Markdown
Contributor

@bradleyjames

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 /oz-review on this pull request to retrigger a review (up to 3 times on the same pull request).

Powered by Oz

@oz-for-oss oz-for-oss Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Comment thread crates/languages/grammars/markdown/highlights.scm
@oz-for-oss oz-for-oss Bot requested a review from kevinyang372 June 28, 2026 01:50
oz-for-oss[bot]
oz-for-oss Bot previously requested changes Jun 28, 2026

@oz-for-oss oz-for-oss Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Comment thread crates/syntax_tree/src/queries/highlight_query.rs Outdated
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).
@bradleyjames

Copy link
Copy Markdown
Contributor Author

/oz-review

@oz-for-oss

oz-for-oss Bot commented Jun 28, 2026

Copy link
Copy Markdown
Contributor

@bradleyjames

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: @kevinyang372.

Comment /oz-review on this pull request to retrigger a review (up to 3 times on the same pull request).

Powered by Oz

@oz-for-oss oz-for-oss Bot dismissed their stale review June 28, 2026 03:31

Oz no longer requests changes for this pull request after the latest automated review.

@oz-for-oss oz-for-oss Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 kevinyang372 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good progress here! Have a few feedback on this

Comment thread crates/languages/grammars/markdown/highlights.scm
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

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@bradleyjames bradleyjames Jun 30, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread crates/syntax_tree/src/lib.rs Outdated
Comment thread crates/syntax_tree/src/queries/highlight_query.rs Outdated
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cla-signed external-contributor Indicates that a PR has been opened by someone outside the Warp team.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Markdown syntax highlighting

2 participants