getzola / zola

A fast static site generator in a single binary with everything built-in. https://www.getzola.org
https://www.getzola.org
MIT License
13.42k stars 940 forks source link

Dracula syntax highlighting is off #1423

Open ibraheemdev opened 3 years ago

ibraheemdev commented 3 years ago

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 commented 3 years ago

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

ibraheemdev commented 3 years ago

gruvbox-dark seems to work fine: image

Keats commented 3 years ago

Looks like a bug with the Dracula theme then :/

doamatto commented 3 years ago

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 commented 3 years ago

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 commented 3 years ago

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.

blueglyph commented 1 year ago

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 }

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 commented 1 year ago

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:

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 commented 1 year ago

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.

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