Closed jennybc closed 2 months ago
Positron dark theme, which is the most massive improvement in this PR:
We're trying to match (or do better than!) what GitHub does -- notice that mean()
is not highlighted as a function call, but it should be.
With this PR, Positron still uses a light theme, but still a big improvement. Notice that we syntax highlight mean()
as a function call.
Before this PR is very bad.
RStudio dark theme, which is also indicative of where Positron will be once it provides info re: dark vs light theme.
We're trying to match (or do better than!) what GitHub does -- notice that mean()
is not highlighted as a function call, but it should be.
With this PR, RStudio newly honors a dark theme. Notice that we syntax highlight mean()
as a function call.
Before this PR, RStudio looked fine, but used a light theme unconditionally.
Positron light theme
We're trying to match (or do better than!) what GitHub does -- notice that mean()
is not highlighted as a function call, but it should be.
With this PR. Notice that we syntax highlight mean()
as a function call.
Before this PR. You can still see there is a problem with the background color (i.e. the code chunk does not stand out against the background), but it's less of an eyesore than the dark mode case.
RStudio light theme
We're trying to match (or do better than!) what GitHub does -- notice that mean()
is not highlighted as a function call, but it should be.
With this PR. Notice that we syntax highlight mean()
as a function call.
Before this PR.
@hadley @cderv I'm happy to get feedback, but I mostly tagged you here for awareness. A minimal fix for the target issue here in reprex is relatively small. The main value of the PR might be identifying the changes we should try to make elsewhere: the KDE syntax highlighting definition file for R (affects all R highlighted by Pandoc) and how GitHub approaches highlighting for R.
how GitHub approaches highlighting for R
Thanks for sharing all this ! I think this will be useful to improve Github Preview format in R Markdown and Quarto.
FWIW re GitHub updating to (presumably) use TreeLights for R:
I just heard back from an engineer on the the team and they said that the work to fix the syntax highlighting is currently not prioritized. Someone from that team will reach out when they upgrade the highlighting, if they need help verifying the changes. The team has an internal issue open about your request.
So probably not in the cards anytime soon, but at least its on their radar now
Thanks for the update @DavisVaughan. Given that forecast, maybe we should consider upgrading the textmate grammar for R? That might dovetail with making some upgrades to the KDE syntax definition (the Pandoc side of the house).
The vendored grammar appears to live here: https://github.com/github-linguist/linguist/tree/f0aebbe90d3b9b9bae5b7258f99370def1ee489f/vendor
with the true grammar source being regarded as this: https://github.com/textmate/r.tmbundle
I see both @hadley and Jim Hester have contributed there at some point in the past, so it's possible it's already as good as it gets (?). But I get better highlighting of R in VS Code than on GitHub and I think that's also using a textmate grammar, so that gives me hope.
Updated: I see that the true grammar source for some languages smells associated with VS Code or VS Code extensions. So that might be another low effort improvement, i.e. convince GitHub to consult a differen source for the R grammar.
WOW, that was a long time ago
Fixes #468
Several changes to reprex's html preview:
rstudioapi::getThemeInfo()
, with light mode as the fall back.rstudioapi::getThemeInfo()
yet (https://github.com/posit-dev/positron/issues/2986), but it will. In the meantime, reprex html preview will be in light mode, but that's still an improvement on the status quo.color
andbackground-color
for<body>
, plus a few other tweaks 11eca0dd4c2d39317ec559d5ed809e6eac151c78.rmarkdown::pandoc_convert()
(for md-to-html conversion) in a more canonical way, which allows us to eliminate the use of a template.468 could be fixed just by making sure to specify both the
color
andbackground-color
for<body>
. But while I was working on this, I noticed various weird things about how R code is highlighted both on GitHub and by Pandoc! So I dug into that, which explains my forays into a custom theme and syntax definition. Hopefully this will lead to some improvements outside of reprex for syntax highlighting of R.GitHub side quest
I said that PrettyLights is the current highlighter for R. According to https://github.com/wooorm/starry-night:
The textmate grammar that Github + PrettyLights uses for R has some shortcomings, such as not properly tokenizing / classing function calls. This is related to a separate problem @DavisVaughan has noticed, which is that click-on-a-reference doesn't pull up the symbols pane (whereas click-on-a-definition does). Davis poked at this a bit and now he's got a ticket into the right system to see if his recent tree-sitter + R successes at GitHub could possibly lead to R becoming one of the languages handled with TreeLights. I think this would lead to better syntax highlighting of R, among other benefits.
KDE Syntax-Highlighting side quest
Source: https://pandoc.org/chunkedhtml-demo/13-syntax-highlighting.html
Indeed I was not satisfied with the built-in highlighting, so I did have a look at KDE's repository of syntax definitions. I think the R syntax definition used by Pandoc has some strange, suboptimal choices. Here it is in various places, in increasing order of importance:
I engaged @cderv in some discussions around this XML and he's in agreement that we could improve it. And he has made a successful merge request before.
I opened an issue to discuss with maintainers: https://invent.kde.org/frameworks/syntax-highlighting/-/issues/32
Here are a few easy tweaks in this PR: 5679f011712eda932fba8da43c7c87c712db4356