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

C++ string bug when using a '%' character #509

Open
P-E-Meunier opened this issue Dec 25, 2023 · 0 comments
Open

C++ string bug when using a '%' character #509

P-E-Meunier opened this issue Dec 25, 2023 · 0 comments

Comments

@P-E-Meunier
Copy link

P-E-Meunier commented Dec 25, 2023

When using the C or C++ parser, the '%' character in a string is misinterpreted as a "placeholder".

This can be observed by trying to format "% + 10px". Syntect outputs <span class="constant other placeholder c">% + 10p</span>x instead of the expected % + 10px.

Complete example:

extern crate syntect;
use syntect::util::{LinesWithEndings};
use syntect::html::{ClassedHTMLGenerator, ClassStyle};
fn main() {
    let syntax_set = syntect::parsing::SyntaxSet::load_defaults_newlines();
    let syntax = syntax_set.find_syntax_by_extension("c++").unwrap();
    let mut h = ClassedHTMLGenerator::new_with_class_style(syntax, &syntax_set, ClassStyle::Spaced);
    for line in LinesWithEndings::from(r#""% + 10px""#) {
        h.parse_html_for_line_which_includes_newline(line).unwrap();
    }
    assert_eq!(h.finalize(), r#"<span class="source c++"><span class="string quoted double c"><span class="punctuation definition string begin c">&quot;</span>% + 10px<span class="punctuation definition string end c">&quot;</span></span></span>"#);
}
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

1 participant