diff --git a/src/languages/cpp.js b/src/languages/cpp.js index 4b85b773ac..f91e3f4a61 100644 --- a/src/languages/cpp.js +++ b/src/languages/cpp.js @@ -15,13 +15,16 @@ function(hljs) { className: 'string', variants: [ { - begin: '(u8?|U)?L?"', end: '"', + begin: '(u8?|U|L)?"', end: '"', illegal: '\\n', contains: [hljs.BACKSLASH_ESCAPE] }, { - begin: '(u8?|U)?R"', end: '"', - contains: [hljs.BACKSLASH_ESCAPE] + // TODO: This does not handle raw string literals with prefixes. Using + // a single regex with backreferences would work (note to use *? + // instead of * to make it non-greedy), but the mode.terminators + // computation in highlight.js breaks the counting. + begin: '(u8?|U|L)?R"\\(', end: '\\)"', }, { begin: '\'\\\\?.', end: '\'', diff --git a/test/markup/cpp/string-literals.expect.txt b/test/markup/cpp/string-literals.expect.txt index c4ae2e38ff..1210b01e5e 100644 --- a/test/markup/cpp/string-literals.expect.txt +++ b/test/markup/cpp/string-literals.expect.txt @@ -9,19 +9,19 @@ // Raw string literals (multiline) auto char_multi = R"(Hello -normal +"normal" muliline string.)"; auto utf8_multi = u8R"(Hello -utf-8 +"utf-8" muliline string)"; auto utf16_multi = uR"(Hello -utf-16 +"utf-16" muliline string)"; auto utf32_multi = UR"(Hello -utf-32 +"utf-32" muliline string)"; diff --git a/test/markup/cpp/string-literals.txt b/test/markup/cpp/string-literals.txt index 21f3260737..68b8bd411a 100644 --- a/test/markup/cpp/string-literals.txt +++ b/test/markup/cpp/string-literals.txt @@ -9,19 +9,19 @@ auto wide_char = L"Hello wchar_t string"; // Raw string literals (multiline) auto char_multi = R"(Hello -normal +"normal" muliline string.)"; auto utf8_multi = u8R"(Hello -utf-8 +"utf-8" muliline string)"; auto utf16_multi = uR"(Hello -utf-16 +"utf-16" muliline string)"; auto utf32_multi = UR"(Hello -utf-32 +"utf-32" muliline string)";