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

Rust unsafe keyword should be highlighted differently #1299

Closed
gautammohan opened this issue Aug 8, 2019 · 5 comments
Closed

Rust unsafe keyword should be highlighted differently #1299

gautammohan opened this issue Aug 8, 2019 · 5 comments
Labels
enhancement-request A request for an enhancement to be developed.

Comments

@gautammohan
Copy link

Is your enhancement request related to a problem? Please describe.

Unsafe blocks are uncommon and should be very loudly highlighted in Rust. Most Rust syntax highlighters make the unsafe keyword bright red, however it seems that Rouge groups it with other keywords.

Describe the solution you'd like

Is there a way to capture the "unsafe" keyword and highlight it differently?

Additional context

@gautammohan gautammohan added the enhancement-request A request for an enhancement to be developed. label Aug 8, 2019
@pyrmont
Copy link
Contributor

pyrmont commented Aug 8, 2019

@gautammohan Can you provide some examples of the other syntax highlighters you're talking about? I'm curious how they're tokenising unsafe.

@gautammohan
Copy link
Author

gautammohan commented Aug 8, 2019

I use emacs normally, and rust-mode puts unsafe in a warning/error font face. I may have been overzealous in my statement of "most" syntax highlighters, as I just tried Vim and by default it did not differentiate between unsafeand other keywords as far as highlighting. Let me dial it back to say that Emacs does it, and I think it's a good idea (provided it doesn't take too much effort to implement)

(Link to where I believe they handle unsafe)
https://github.com/rust-lang/rust-mode/blob/c62185ae1c6edf0335261f169241eb8ee9713ad5/rust-mode.el#L669

@pyrmont
Copy link
Contributor

pyrmont commented Aug 8, 2019

Hmmm... the problem is that there's not really a token that would be appropriate for unsafe other than the Keyword token we're currently using. Rouge uses the same tokens as Pygments and that system isn't really designed to provide the kind of support for which you're looking.

What's the use case? Are you wanting to have the same kind of highlighting in a blog post?

@gautammohan
Copy link
Author

Yep, highlighting in a blog post is precisely the use case. A potential workaround (for my case) would probably be to create a special tag and amend my css files.

I wasn't sure if it was an easy fix or not, but it looks like it might not be trivial. I'm not even sure if the Rust community agrees on a canonical syntax highlighting style. If it turns out that many of the tools treat unsafe differently, it might be worth considering. However I do not know for sure if this is the case.

@pyrmont
Copy link
Contributor

pyrmont commented Aug 9, 2019

I don't know how much control you have over the server but you might be interested in looking into the Escape lexer that was added in v3.4.0 of Rouge. If you have a formatter that has escaping enabled, you should be able to insert HTML into your source code that will be 'ignored' by Rouge and passed straight through to your blogging engine.

We need to document its use better and so you might prefer a different way of achieving your goal but if you're curious about this, PR #1152 (where it was added) is a good place to start. I hope that's helpful!

@pyrmont pyrmont closed this as completed Aug 12, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement-request A request for an enhancement to be developed.
Projects
None yet
Development

No branches or pull requests

2 participants