Commit 90fbf0be283c4d68c74d1754bed06704ea02de8f

Golmote 2015-10-26T08:08:13

Python: Highlight triple-quoted strings before comments. Fix #815

diff --git a/components/prism-python.js b/components/prism-python.js
index eb97f48..e020c9d 100644
--- a/components/prism-python.js
+++ b/components/prism-python.js
@@ -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
diff --git a/components/prism-python.min.js b/components/prism-python.min.js
index 743aa35..cecce9d 100644
--- a/components/prism-python.min.js
+++ b/components/prism-python.min.js
@@ -1 +1 @@
-Prism.languages.python={comment:{pattern:/(^|[^\\])#.*/,lookbehind:!0},string:/"""[\s\S]+?"""|'''[\s\S]+?'''|("|')(?:\\?.)*?\1/,"function":{pattern:/((?:^|\s)def[ \t]+)[a-zA-Z_][a-zA-Z0-9_]*(?=\()/g,lookbehind:!0},"class-name":{pattern:/(\bclass\s+)[a-z0-9_]+/i,lookbehind:!0},keyword:/\b(?:as|assert|async|await|break|class|continue|def|del|elif|else|except|exec|finally|for|from|global|if|import|in|is|lambda|pass|print|raise|return|try|while|with|yield)\b/,"boolean":/\b(?:True|False)\b/,number:/\b-?(?:0[bo])?(?:(?:\d|0x[\da-f])[\da-f]*\.?\d*|\.\d+)(?:e[+-]?\d+)?j?\b/i,operator:/[-+%=]=?|!=|\*\*?=?|\/\/?=?|<[<=>]?|>[=>]?|[&|^~]|\b(?:or|and|not)\b/,punctuation:/[{}[\];(),.:]/};
\ No newline at end of file
+Prism.languages.python={"triple-quoted-string":{pattern:/"""[\s\S]+?"""|'''[\s\S]+?'''/,alias:"string"},comment:{pattern:/(^|[^\\])#.*/,lookbehind:!0},string:/("|')(?:\\?.)*?\1/,"function":{pattern:/((?:^|\s)def[ \t]+)[a-zA-Z_][a-zA-Z0-9_]*(?=\()/g,lookbehind:!0},"class-name":{pattern:/(\bclass\s+)[a-z0-9_]+/i,lookbehind:!0},keyword:/\b(?:as|assert|async|await|break|class|continue|def|del|elif|else|except|exec|finally|for|from|global|if|import|in|is|lambda|pass|print|raise|return|try|while|with|yield)\b/,"boolean":/\b(?:True|False)\b/,number:/\b-?(?:0[bo])?(?:(?:\d|0x[\da-f])[\da-f]*\.?\d*|\.\d+)(?:e[+-]?\d+)?j?\b/i,operator:/[-+%=]=?|!=|\*\*?=?|\/\/?=?|<[<=>]?|>[=>]?|[&|^~]|\b(?:or|and|not)\b/,punctuation:/[{}[\];(),.:]/};
\ No newline at end of file
diff --git a/tests/languages/python/string_feature.test b/tests/languages/python/string_feature.test
index fbb6fea..8c7b6bb 100644
--- a/tests/languages/python/string_feature.test
+++ b/tests/languages/python/string_feature.test
@@ -1,9 +1,3 @@
-"""foobar"""
-"""fo"o
-bar"""
-'''foobar'''
-'''fo'o
-bar'''
 ""
 "fo\"obar"
 ''
@@ -12,10 +6,6 @@ bar'''
 ----------------------------------------------------
 
 [
-	["string", "\"\"\"foobar\"\"\""],
-	["string", "\"\"\"fo\"o\r\nbar\"\"\""],
-	["string", "'''foobar'''"],
-	["string", "'''fo'o\r\nbar'''"],
 	["string", "\"\""],
 	["string", "\"fo\\\"obar\""],
 	["string", "''"],
diff --git a/tests/languages/python/triple-quoted-string_feature.test b/tests/languages/python/triple-quoted-string_feature.test
new file mode 100644
index 0000000..ab1e2ab
--- /dev/null
+++ b/tests/languages/python/triple-quoted-string_feature.test
@@ -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.
\ No newline at end of file