Skip to content

fix: syntax highlighting for markdown files#320

Open
tenox7 wants to merge 2 commits into
eugenioenko:mainfrom
tenox7:fix/markdown-syntax-highlighting
Open

fix: syntax highlighting for markdown files#320
tenox7 wants to merge 2 commits into
eugenioenko:mainfrom
tenox7:fix/markdown-syntax-highlighting

Conversation

@tenox7

@tenox7 tenox7 commented Jul 4, 2026

Copy link
Copy Markdown

Problem

Opening a .md file shows no syntax highlighting even though chroma matches the markdown lexer.

Root cause

Chroma's markdown lexer emits mostly Generic* token types — GenericHeading (#), GenericSubheading (##+), GenericStrong (**bold**), GenericEmph (*italic*). mapTokenType() in internal/core/highlight/highlighter.go only handled programming-language categories (Keyword, String, Comment, Name*, ...), so all Generic tokens fell through to StyleDefault and were dropped. Markdown files rendered almost entirely unstyled.

Fix

Map Generic token types to existing theme styles:

Token Style
GenericHeading / GenericSubheading StyleSyntaxKeyword
GenericStrong StyleSyntaxType
GenericEmph StyleSyntaxString
GenericInserted / GenericDeleted StyleDiffAdded / StyleDiffDeleted

The Inserted/Deleted mapping also gives .diff/.patch files +/- line coloring for free.

No new styles or theme changes needed — all mappings reuse existing term.Style* constants.

Tests

Added TestHighlightMarkdown and TestHighlightDiff unit tests covering headings, bold, italic, inline code, and diff +/- lines.

Known limitation (unchanged)

Fenced code blocks (```go) still render as plain text — highlighting is per-line and fences require multi-line lexer state. Separate, larger change.

Chroma's markdown lexer emits Generic* token types (GenericHeading,
GenericStrong, GenericEmph) which mapTokenType did not handle, so
headings, bold, and italic text rendered unstyled. Map them to
existing syntax styles. GenericInserted/GenericDeleted are also
mapped, giving .diff/.patch files +/- line coloring.
@tenox7 tenox7 requested a review from eugenioenko as a code owner July 4, 2026 09:33
Copilot AI review requested due to automatic review settings July 4, 2026 09:33

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes missing syntax highlighting for Markdown (and improves diff/patch highlighting) by mapping Chroma’s Generic* token types to existing term.Style* theme styles, and adds unit tests to cover the new behavior.

Changes:

  • Extend mapTokenType() to style GenericHeading/Subheading, GenericStrong, GenericEmph, and GenericInserted/Deleted.
  • Add unit tests for Markdown and diff highlighting.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
internal/core/highlight/highlighter.go Maps Chroma Generic* token types to existing theme styles so Markdown/diff tokens aren’t dropped as StyleDefault.
internal/core/highlight/highlighter_test.go Adds coverage for Markdown headings/bold/italic/inline-code and diff +/- lines.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread internal/core/highlight/highlighter.go Outdated
Comment on lines +106 to +109
case t == chroma.GenericInserted:
return term.StyleSuccess
case t == chroma.GenericDeleted:
return term.StyleDanger
Comment on lines +101 to +102
assertSpanStyle(t, h, "+added line", term.StyleSuccess)
assertSpanStyle(t, h, "-removed line", term.StyleDanger)
Use StyleDiffAdded/StyleDiffDeleted instead of StyleSuccess/StyleDanger
so .diff/.patch files match the app's diff view theming.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants