syntect icon indicating copy to clipboard operation
syntect copied to clipboard

css_for_theme_with_class_style outputs invalid CSS with default Solarized themes

Open Bauke opened this issue 5 years ago • 4 comments

Running the following and then validating the CSS files with your IDE/validator of choice results in the Solarized themes outputting invalid CSS.

let ts = syntect::highlighting::ThemeSet::load_defaults();
for (key, theme) in ts.themes {
  let css = syntect::html::css_for_theme_with_class_style(&theme, syntect::html::ClassStyle::Spaced);
  std::fs::write(format!("{}.css", key), css).unwrap();
}

Solarized (dark) and Solarized (light) end up outputting this selector which is invalid:

.storage.modifier.c++ {
 color: #859900;
}

In Firefox, a CSS error is shown in the console:

Dangling combinator.  Ruleset ignored due to bad selector. (Solarized.css:445:36)

Bauke avatar Sep 01 '20 17:09 Bauke

Looks like we need to escape the CSS class names: https://www.w3.org/International/questions/qa-escapes#css_identifiers

keith-hall avatar Sep 02 '20 06:09 keith-hall

Would it be possible to change c++ to cpp? Or would this affect other parts of syntect besides ClassedHTMLGenerator?

I am currently using str.replace("c++", "cpp") after generating CSS, and after finalize().

mhatzl avatar Jun 22 '23 22:06 mhatzl

Would it be possible to change c++ to cpp? Or would this affect other parts of syntect besides ClassedHTMLGenerator?

As syntect is just a library, it wouldn't affect syntect itself, but for that reason, I don't feel like it is syntect's job to arbitrarily rewrite things, especially as consumers are free to provide their own syntax sets. This syntax comes from Sublime Text, where it would be a breaking change because lots of functionality relies on scopes, like (user customized) keybindings, metadata which controls indentation, comments, completions etc.

keith-hall avatar Jul 01 '23 18:07 keith-hall

Thanks for your reply. I guess Sublime Text won't change anything on their side. If syntect also won't change it, the generated CSS classes cannot be used without manual modification due to c++. String replacement is an acceptable workaround, but it feels bad having to try and replace it for every output, because c++ might be included.

mhatzl avatar Jul 02 '23 13:07 mhatzl