highlightjs / highlight.js

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

(rust) raw keyword variable names are not highlighted correctly #3924

Closed JayAndJef closed 4 months ago

JayAndJef commented 7 months ago

Describe the issue In rust, one can put r# before a keyword name to escape it. Highlight.js does not recognize when this happens and instead highlights the keyword name as a keyword.

Which language seems to have the issue? Rust

Are you using highlight or highlightAuto? highlight

Sample Code to Reproduce

pub fn main() {
    let r#use = "hello"; // r#use should be highlighted as a variable
}

Expected behavior In the above code block, r#use should be highlighted as a variable name. Instead, r is highlighted as a variable name and use is highlighted as a keyword.

Additional context

JayAndJef commented 7 months ago

Github seems to have it correct.

joshgoebel commented 7 months ago

A simple rule that matches r#* and applies no scope would fix the issue of false positives here.

Jaebaek-Lee commented 6 months ago

I tried applying a new regex in rust.js to solve the problem. https://regexr.com/ In this regex site (r#)?[a-zA-Z_]\w* With this regex, the r# keyword is properly identified in all cases. It seems to work fine in the test-browser as well.