zola icon indicating copy to clipboard operation
zola copied to clipboard

Dracula syntax highlighting is off

Open ibraheemdev opened this issue 3 years ago • 6 comments

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

ibraheemdev avatar Mar 30 '21 13:03 ibraheemdev

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

Keats avatar Mar 30 '21 13:03 Keats

gruvbox-dark seems to work fine: image

ibraheemdev avatar Mar 30 '21 13:03 ibraheemdev

Looks like a bug with the Dracula theme then :/

Keats avatar Mar 30 '21 14:03 Keats

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.

doamatto avatar Jun 14 '21 05:06 doamatto

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?

ebkalderon avatar Sep 09 '21 05:09 ebkalderon

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.

Keats avatar Sep 09 '21 06:09 Keats

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 avatar May 04 '23 13:05 blueglyph

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 avatar May 09 '23 08:05 blueglyph

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

blueglyph avatar May 17 '23 08:05 blueglyph