You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Apply .gitattributes syntax highlighting to code-review #10157
A file called .gitattributes in the root of a project tells Github how to color-code / syntax highlight unknown files.
*.myext linguist-language=JavaScript
Would tell Github to display all *myext files like it would display Javascript files - e.g. const abc would make the word const reddish and abc blueish.
However this only applies when looking at a file in the code file viewer. When reviewing such a file in a PR in the code-review panel it uses the plain, non-color coded text only mode.
I would like that it applies the same color coding in a code review as it does in the file view 🙏🏻
Correct. Space is just two characters; syntax highlighting means having to understand all the languages you're looking to highlight. Completely different effort. It's possible but it's not what Refined GitHub does.
Alright will do - just so that this isn't a misunderstanding - I don't mean this should work with every file for every repo. I just meant it could check if there are mappings set up in the current repo for the current file and if so allows for color coding.
I dug into this a bit more, and I think it is possible for an extension, because GitHub already computes the highlighting and ships it to the browser. It just does so on the file view, not on the new "Files changed" view.
The gap. On rust-lang/rust#163493 (public), rust-lang's .gitattributes has *.fixed linguist-language=Rust. In the new /changes view, tests/ui/resolve/struct-shorthand-typo.fixed renders with zero pl-* spans, while its near-identical twin struct-shorthand-typo.rs in the same PR has 172. The classic diff view does color the .fixed file.
The data is already there. The file view (/<owner>/<repo>/blob/<sha>/<path>) embeds "language":"Rust" (with the override applied) and a colorizedLines array: one ready-made HTML string per line, using the same pl-* classes the diff view's CSS already styles.
The new view is easy to map onto:
table[aria-label="Diff for: <path>"] per file
td.diff-text-cell[data-diff-side="left|right"][data-line-number] per line
.diff-text-inner holds the text; the parent <code> already has syntax-highlighted-line
The page's embedded data has pullRequestsChangesRoute.comparison.fullDiff.baseOid / headOid
Proof of concept. Fetch the blob page at baseOid for the left side and at headOid for the right side. For each diff line, take colorizedLines[lineNumber - 1], and replace .diff-text-inner only if the text content is identical. That guard means a wrong mapping can never change what the reviewer reads.
Result on the PR above: 44/44 lines of the .fixed file painted, 0 mismatches. On a private repo with *.aktion linguist-language=JavaScript: 52/52, 0 mismatches.
Before / after (same page, new Files changed view):
DevTools snippet (paste on any /pull/<n>/changes page)
Re-apply after React re-renders and as the virtualized list mounts rows (a MutationObserver)
Play nicely with show-whitespace, which the naive innerHTML swap currently overwrites
Accept the cost of up to two extra same-origin requests per uncolored file, and a dependency on the embedded-data shape, which isn't a public API
So it's fair to say it's more effort or risk than you want to take on. But "extensions can't" doesn't hold: GitHub does the highlighting, and the extension only has to move it from one page to the other. I've also reported the underlying gap to GitHub, since the real fix belongs there: https://github.com/orgs/community/discussions/163932#discussioncomment-18682066
Thanks for looking at this anyways - and kudos to this great extension, I really like it and it helps me a lot every day 🙏🏻
Activity
fregante commentedon Sep 30, 2026
This is not a GitHub support repo. Extensions can't change what GitHub does with files.
Primajin commentedon Sep 30, 2026
Huh, so the extension can do amazing things like show and hide white spaces in the code-review tab, but it can not apply colors?
fregante commentedon Sep 30, 2026
Correct. Space is just two characters; syntax highlighting means having to understand all the languages you're looking to highlight. Completely different effort. It's possible but it's not what Refined GitHub does.
fregante commentedon Sep 30, 2026
By the way, the PR Files view is in beta, so please do report it to GitHub, it's possible that they just haven't noticed yet.
Primajin commentedon Sep 30, 2026
Alright will do - just so that this isn't a misunderstanding - I don't mean this should work with every file for every repo. I just meant it could check if there are mappings set up in the current repo for the current file and if so allows for color coding.
I dug into this a bit more, and I think it is possible for an extension, because GitHub already computes the highlighting and ships it to the browser. It just does so on the file view, not on the new "Files changed" view.
The gap. On rust-lang/rust#163493 (public), rust-lang's
.gitattributeshas*.fixed linguist-language=Rust. In the new/changesview,tests/ui/resolve/struct-shorthand-typo.fixedrenders with zeropl-*spans, while its near-identical twinstruct-shorthand-typo.rsin the same PR has 172. The classic diff view does color the.fixedfile.The data is already there. The file view (
/<owner>/<repo>/blob/<sha>/<path>) embeds"language":"Rust"(with the override applied) and acolorizedLinesarray: one ready-made HTML string per line, using the samepl-*classes the diff view's CSS already styles.The new view is easy to map onto:
table[aria-label="Diff for: <path>"]per filetd.diff-text-cell[data-diff-side="left|right"][data-line-number]per line.diff-text-innerholds the text; the parent<code>already hassyntax-highlighted-linepullRequestsChangesRoute.comparison.fullDiff.baseOid/headOidProof of concept. Fetch the blob page at
baseOidfor the left side and atheadOidfor the right side. For each diff line, takecolorizedLines[lineNumber - 1], and replace.diff-text-inneronly if the text content is identical. That guard means a wrong mapping can never change what the reviewer reads.Result on the PR above: 44/44 lines of the
.fixedfile painted, 0 mismatches. On a private repo with*.aktion linguist-language=JavaScript: 52/52, 0 mismatches.Before / after (same page, new Files changed view):
DevTools snippet (paste on any
/pull/<n>/changespage)What a real feature would still need:
MutationObserver)show-whitespace, which the naiveinnerHTMLswap currently overwritesSo it's fair to say it's more effort or risk than you want to take on. But "extensions can't" doesn't hold: GitHub does the highlighting, and the extension only has to move it from one page to the other. I've also reported the underlying gap to GitHub, since the real fix belongs there: https://github.com/orgs/community/discussions/163932#discussioncomment-18682066
Thanks for looking at this anyways - and kudos to this great extension, I really like it and it helps me a lot every day 🙏🏻