Skip to content

Commit

Permalink
Python: Highlight triple-quoted strings before comments. Fix #815
Browse files Browse the repository at this point in the history
  • Loading branch information
Golmote committed Oct 26, 2015
1 parent 81933ee commit 90fbf0b
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 12 deletions.
6 changes: 5 additions & 1 deletion components/prism-python.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
Prism.languages.python= {
'triple-quoted-string': {
pattern: /"""[\s\S]+?"""|'''[\s\S]+?'''/,
alias: 'string'
},
'comment': {
pattern: /(^|[^\\])#.*/,
lookbehind: true
},
'string': /"""[\s\S]+?"""|'''[\s\S]+?'''|("|')(?:\\?.)*?\1/,
'string': /("|')(?:\\?.)*?\1/,
'function' : {
pattern: /((?:^|\s)def[ \t]+)[a-zA-Z_][a-zA-Z0-9_]*(?=\()/g,
lookbehind: true
Expand Down
2 changes: 1 addition & 1 deletion components/prism-python.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 0 additions & 10 deletions tests/languages/python/string_feature.test
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
"""foobar"""
"""fo"o
bar"""
'''foobar'''
'''fo'o
bar'''
""
"fo\"obar"
''
Expand All @@ -12,10 +6,6 @@ bar'''
----------------------------------------------------

[
["string", "\"\"\"foobar\"\"\""],
["string", "\"\"\"fo\"o\r\nbar\"\"\""],
["string", "'''foobar'''"],
["string", "'''fo'o\r\nbar'''"],
["string", "\"\""],
["string", "\"fo\\\"obar\""],
["string", "''"],
Expand Down
21 changes: 21 additions & 0 deletions tests/languages/python/triple-quoted-string_feature.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
"""foobar"""
"""fo"o
#bar
baz"""
'''foobar'''
'''fo'o
#bar
baz'''

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

[
["triple-quoted-string", "\"\"\"foobar\"\"\""],
["triple-quoted-string", "\"\"\"fo\"o\r\n#bar\r\nbaz\"\"\""],
["triple-quoted-string", "'''foobar'''"],
["triple-quoted-string", "'''fo'o\r\n#bar\r\nbaz'''"]
]

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

Checks for triple-quoted strings.

0 comments on commit 90fbf0b

Please sign in to comment.