highlightjs / highlight.js

JavaScript syntax highlighter with language auto-detection and zero dependencies.
https://highlightjs.org/
BSD 3-Clause "New" or "Revised" License
23.6k stars 3.58k forks source link

[Request] Updated union type keywords in Rust #3948

Closed Jaebaek-Lee closed 9 months ago

Jaebaek-Lee commented 9 months ago

Is your request related to a specific problem you're having? Rust supports keywords of type union. doc.1 doc.2

But union hasn't been added to the rust.js keyword list in highlight.js yet - all the other keywords are included. https://github.com/highlightjs/highlight.js/blob/8b88a7d4c3e88f157a87b8d50088af329d700eeb/src/languages/rust.js#L73C4-L77C15

The solution you'd prefer / feature you'd like to see added... Add the union string to the list of keywords in rust.js.

Any alternative solutions you considered... When you use union as a purposeful type in your code, it is designed to be properly highlighted. It's just not included in the KEYWORDS array. So maybe you don't need to modify anything. However, if the KEYWORDS array should contain all the keywords supported by rust, it seems like a good idea to add union as well. https://github.com/highlightjs/highlight.js/blob/8b88a7d4c3e88f157a87b8d50088af329d700eeb/src/languages/rust.js#L287-L296

Additional context...

as is

image

to be

image

joshgoebel commented 9 months ago

What's an example of where union is used in Rust outside of defining a new class/data type?

Jaebaek-Lee commented 9 months ago

As far as I know, the union keyword is not used except when defining a new union. The same goes for enum and struct, but they are all included in KEYWORDS, so I'm just suggesting it. 😊

joshgoebel commented 9 months ago

The same goes for enum and struct, but they are all included in KEYWORDS

Ha, well that's a good argument.