Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dracula syntax highlighting is off #1423

Open
ibraheemdev opened this issue Mar 30, 2021 · 9 comments
Open

Dracula syntax highlighting is off #1423

ibraheemdev opened this issue Mar 30, 2021 · 9 comments

Comments

@ibraheemdev
Copy link
Contributor

The syntax highlighting Dracula theme currently underlines a lot of code that should not be underlined. This is an example rust code block:
image

@Keats
Copy link
Collaborator

Keats commented Mar 30, 2021

Is this only on Dracula or on any themes? The rust syntax shipped is pretty old.

@ibraheemdev
Copy link
Contributor Author

gruvbox-dark seems to work fine:
image

@Keats
Copy link
Collaborator

Keats commented Mar 30, 2021

Looks like a bug with the Dracula theme then :/

@ibraheemdev ibraheemdev changed the title Dracula syntax hightling is off Dracula syntax highlighting is off Mar 31, 2021
@doamatto
Copy link
Contributor

If this happens to be the outdated syntax tool, perhaps we should add Whitesource or Dependabot to help keep things up-to-date. In the meantime, I'll take a crack at trying to find the root cause, if it happens to be more than just an outdated dep.

@ebkalderon
Copy link

There seem to be more issues here too. The variables and identifiers in this code block styled with the charcoal theme are supposed to be white instead of orange:

Screenshot from 2021-09-09 00-55-27

Orange is the accent color of this particular Zola site, and previously, the currently active Highlight theme would override the default orange color of this code block text, but not anymore. Not sure if this is a related bug or something deserving of filing a new ticket?

I can confirm that gruvbox-dark doesn't have the orange text problem for me as well, as @ibraheemdev suggested above. Perhaps there are some bugs with a few of the themes?

@Keats
Copy link
Collaborator

Keats commented Sep 9, 2021

Perhaps there are some bugs with a few of the themes?

It's likely.
The syntax definitions for Rust for example are also pretty old now as syntect doesn't support the latest features.

ebkalderon added a commit to ebkalderon/zerm that referenced this issue Nov 15, 2022
There are some Zola highlight themes and syntax definitions that don't
work very well, and as such, they sometimes fall back to the base text
color provided by the Zola theme. If the base text color is not neutral,
e.g. white or black, the code highlighting can look quite terrible, as
shown in getzola/zola#1423.

It would be nice if the `code` tag defaulted to `var(--color)` instead
of `var(--accent)` to avoid breaking several built-in Zola highlight
themes. With that said, if there's enough opposition to this change,
it's okay; I'm willing to just override the CSS in my own project to fix
the highlight themes.
ebkalderon added a commit to ebkalderon/ebkalderon.github.io that referenced this issue Nov 15, 2022
@blueglyph
Copy link

Indeed, it looks like a limitation of the parser.

I've tried to adapt a theme, but it's easy to see by using highlight_theme = "css" in the configuration that the parser is confused about many elements.

I think that if it could at least recognize the keywords (like self, const, ...), it may help a little. In the following code:

forward_ref_binop! { impl const Shl, shl for $t, $f }
  • 'impl' is storage.type.impl.rust
  • 'const', 'Shl', 'shl', and 'for' are entity.name.impl.rust, and so 'const' and 'for' cannot be distinguished as language elements.

In the function definition below, both 'self' and 'f' are variable.parameter.rust, so 'self' cannot be distinguished as language element:

fn fmt(&self, f: &mut Formatter<'_>)

@blueglyph
Copy link

The Sublime syntax file is very old, its last modification was done in 2019.

I've tried with another file I found in the rust-lang repository:

https://github.com/rust-lang/rust-enhanced/blob/master/RustEnhanced.sublime-syntax

(Note: you must rename Rust Enhanced to Rust at the top)

Despite that, I find it hard to get any satisfactory result. I don't know if that's a limitation of the parsing system used by Sublime or if it's due to the syntax file itself. For example, the word other below is in a different group in each case:

  • z-meta z-block z-rust:

    fn shl(self, other: U) -> T {
        self << other
    }
  • z-meta z-group z-rust (also used for macros...):

    fn add_mod(self, other: Self, m: Self) -> Self::Output {
        (self + other) % m
    }

So either I leave many groups in the same neutral colour, or it ends up in a mess of inconcistent colours.

Has anyone tried other recent syntax files?

@blueglyph
Copy link

blueglyph commented May 17, 2023

This issue doesn't seem to be active anymore. For anyone looking for a fix, I'll just include my modified version of Rust.sublime-syntax, that I patched to get slightly better results for the Rust language.

  • took the latest revision (2f0050f6) in https://github.com/sublimehq/Packages, since the one pointed by Zola is very old; this latest one is only 5 months old
  • added self to variable.language.rust to distinguish it from other parameters
  • fixed let, const, and static which were storage.type.rust (that includes a lot of other things like identifiers), and moved them to keyword.other.rust.

This file replaces sublime\syntaxes\Packages\Rust\Rust.sublime-syntax, which is in a Git submodule. I won't commit it in its original repository since it likely breaks some tests and is incompatible with older versions. The fact it's a submodule of Zola also makes it more complicated to update here - I'm using a custom version that I compiled to generate websites.

The packed file must be rebuilt after each modification of the syntax file, before compiling Zola:

cd components\config
cargo run --example generate_sublime synpack ../../sublime/syntaxes ../../sublime/syntaxes/newlines.packdump

To get optimal results, it's best to adapt the theme file but it should already give better results with existing themes.

Rust.zip

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

No branches or pull requests

5 participants