8000 WriteCSS not outputting rule for NameBuiltinPseudo · Issue #346 · alecthomas/chroma · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

WriteCSS not outputting rule for NameBuiltinPseudo #346

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

Closed
acahir opened this issue Apr 5, 2020 · 6 comments
Closed

WriteCSS not outputting rule for NameBuiltinPseudo #346

acahir opened this issue Apr 5, 2020 · 6 comments

Comments

@acahir
Copy link
acahir commented Apr 5, 2020

Description

When using WriteCSS to autogenerate CSS rules (through Hugo v63.8, but traced that call back to chroma/html.go), the NameBuiltinPseudo CSS (".bp") class is never output.

It's possible this is by design, but I couldn't find a reason why in the code (Not much experience with Go, sorry). Either way, that CSS class is generated during processing for at least Swift, not sure about other languages.

To Reproduce

echo "print(\"Hello World\")" | ./chroma --html --html-only --lexer=swift
generates:

<pre class="chroma"><span class="bp">print</span><span class="p">(</span><span class="s">&#34;Hello World&#34;</span><span class="p">)</span>
</pre>

./chroma --html-styles | grep bp
gives no output

@alecthomas
Copy link
Owner

This is somewhat deliberate, though perhaps a bit confusing. Basically if a particular style's token type evaluates to the same as the background, it will not be emitted.

For example, the abap style has a white background and NameBuiltinPseudo is black, so is thus emitted:

$ echo "print(\"Hello World\")" | chroma --style=abap --html --lexer=swift | less | grep bp
/* NameBuiltinPseudo */ .chroma .bp { color: #000000 }
<pre class="chroma"><span class="bp">print</span><span class="p">(</span><span class="s">&#34;Hello World&#34;</span><span class="p">)</span>

Effectively this should cause no issues; are you seeing some problems due to this?

@acahir
Copy link
Author
acahir commented Apr 12, 2020

Think I get it, basically leaving out unneeded classes.

Yea, I did notice this because of a problem. I had used the WriteCSS function to generate a list of css as a starting point to customize the styling. I had noticed once before that a class wasn't output, but at the time didn't trace it back to the function call in Chroma (since it was used through hugo).

I noticed it again recently adding a 'dark' theme (with toggle on static site) and noticed some words were black on a now black background. Went looking and found that the .bp class had no definition output, so no where to tell it to change.

Perhaps my understanding of the writeCSS function (called through hugo gen chromastyles --style=monokai > syntax.css) is not the correct way to form a base to customize a style? Given this from the hugo docs, I could see a lot of people going this way once the stylesheet was output.

I'd be happy to submit some changes to the hugo docs on the best way to change anything would be.

Thanks for the response.

@acahir
Copy link
Author
8000 acahir commented Apr 12, 2020

I just noticed in your Chroma docs:

If WithClasses() is used, the corresponding CSS can be obtained from the formatter with:

formatter := html.New(html.WithClasses())
err := formatter.WriteCSS(w, style)

So I guess I'd have the same question. If someone wanted to use WithClasses, and generated a stylesheet with WriteCSS, then I think there's the same potential for missing classes causing a problem if customized. Once those styles are outside Chroma, it can no longer intelligently decide which classes are redundant.

The irony is that I probably chose to use WithClasses partly to avoid the redundant inline styling in the HTML, yet the attempt to remove redundant classes is what cause the problem I ran into.

@alecthomas
Copy link
Owner

That use case makes sense. I've added an option to the HTML formatter to output even the redundant styles. If you'd like to file a bug with Hugo, bep can update gen chromastyles to use this.

@acahir
Copy link
Author
acahir commented Apr 13, 2020

bep is requesting if you could tag a release version to pull?

@alecthomas
Copy link
Owner

Yep, tagged v0.7.2!

mrsdizzie pushed a commit to mrsdizzie/chroma that referenced this issue Jul 15, 2020
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

2 participants
0