Skip to content

Commit

Permalink
Allow escaping line breaks in Python strings
Browse files Browse the repository at this point in the history
  • Loading branch information
FIameCaster committed Apr 4, 2024
1 parent fe7de05 commit 9d297f5
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
6 changes: 3 additions & 3 deletions package/src/prism/languages/python.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ inside[rest] = languages.py = languages.python = {
greedy: true
},
'string-interpolation': {
pattern: /(?:fr?|rf)(?:("""|''')[\s\S]*?\1|(["'])(?:\\.|(?!\2)[^\\\n])*\2)/gi,
pattern: /(?:fr?|rf)(?:("""|''')[\s\S]*?\1|(["'])(?:\\[\s\S]|(?!\2)[^\\\n])*\2)/gi,
greedy: true,
inside: {
'interpolation': {
Expand All @@ -31,12 +31,12 @@ inside[rest] = languages.py = languages.python = {
}
},
'triple-quoted-string': {
pattern: /(?:[rub]|br|rb)?("""|''')[\s\S]*?\1/gi,
pattern: /(?:br?|rb?|u)?("""|''')[\s\S]*?\1/gi,
greedy: true,
alias: 'string'
},
'string': {
pattern: /(?:[rub]|br|rb)?(["'])(?:\\.|(?!\1)[^\\\n])*\1/gi,
pattern: /(?:br?|rb?|u)?(["'])(?:\\[\s\S]|(?!\1)[^\\\n])*\1/gi,
greedy: true
},
'function': {
Expand Down
5 changes: 4 additions & 1 deletion package/src/prism/tests/languages/python/string_feature.test
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
''
'fo\'obar'
"fo\" # comment obar"
"foo\
bar"

r"\n"
b'foo'
Expand All @@ -17,6 +19,7 @@ u"foo"
["string", "''"],
["string", "'fo\\'obar'"],
["string", "\"fo\\\" # comment obar\""],
["string", "\"foo\\\nbar\""],

["string", "r\"\\n\""],
["string", "b'foo'"],
Expand All @@ -26,4 +29,4 @@ u"foo"

----------------------------------------------------

Checks for strings.
Checks for strings.

0 comments on commit 9d297f5

Please # to comment.