Skip to content

Commit

Permalink
fix(rust) prevent symbol from gobbling strings
Browse files Browse the repository at this point in the history
  • Loading branch information
joshgoebel committed Dec 22, 2024
1 parent 93e6358 commit 2db4c16
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/languages/rust.js
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,8 @@ export default function(hljs) {
}),
{
className: 'symbol',
begin: /'[a-zA-Z_][a-zA-Z0-9_]*/
// negative lookahead to avoid matching `'`
begin: /'[a-zA-Z_][a-zA-Z0-9_]*(?!')/
},
{
scope: 'string',
Expand Down
2 changes: 2 additions & 0 deletions test/markup/rust/strings.expect.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<span class="hljs-string">&#x27;<span class="hljs-char escape_">\x</span>1A&#x27;</span>;
<span class="hljs-string">&#x27;<span class="hljs-char escape_">\u</span>12AS&#x27;</span>;
<span class="hljs-string">&#x27;<span class="hljs-char escape_">\U</span>1234ASDF&#x27;</span>;
<span class="hljs-string">&#x27;😭&#x27;</span>;
<span class="hljs-string">b&#x27;a&#x27;</span>;

<span class="hljs-string">&quot;hello&quot;</span>;
Expand All @@ -12,6 +13,7 @@
<span class="hljs-string">r###&quot;world&quot;###</span>;
<span class="hljs-string">r##&quot; &quot;###
&quot;# &quot;##</span>;
<span class="hljs-string">&quot;😭😭😭😭&quot;</span>;

<span class="hljs-string">br&quot; &quot;</span>;
<span class="hljs-string">br#&quot;hello&quot;#</span>;
Expand Down
2 changes: 2 additions & 0 deletions test/markup/rust/strings.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
'\x1A';
'\u12AS';
'\U1234ASDF';
'😭';
b'a';

"hello";
Expand All @@ -12,6 +13,7 @@ r"hello";
r###"world"###;
r##" "###
"# "##;
"😭😭😭😭";

br" ";
br#"hello"#;
Expand Down

0 comments on commit 2db4c16

Please sign in to comment.