Skip to content

Commit

Permalink
JavaScript: Allow for all non-ASCII characters in function names. Fix #…
Browse files Browse the repository at this point in the history
  • Loading branch information
Golmote committed Sep 3, 2015
1 parent 9a9020b commit 29e26dc
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 6 deletions.
3 changes: 2 additions & 1 deletion components/prism-javascript.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
Prism.languages.javascript = Prism.languages.extend('clike', {
'keyword': /\b(as|async|await|break|case|catch|class|const|continue|debugger|default|delete|do|else|enum|export|extends|false|finally|for|from|function|get|if|implements|import|in|instanceof|interface|let|new|null|of|package|private|protected|public|return|set|static|super|switch|this|throw|true|try|typeof|var|void|while|with|yield)\b/,
'number': /\b-?(0x[\dA-Fa-f]+|0b[01]+|0o[0-7]+|\d*\.?\d+([Ee][+-]?\d+)?|NaN|Infinity)\b/,
'function': /(?!\d)[a-z0-9_$]+(?=\()/i
// Allow for all non-ASCII characters (See http://stackoverflow.com/a/2008444)
'function': /[_$a-zA-Z\xA0-\uFFFF][_$a-zA-Z0-9\xA0-\uFFFF]*(?=\()/i
});

Prism.languages.insertBefore('javascript', 'keyword', {
Expand Down
2 changes: 1 addition & 1 deletion components/prism-javascript.min.js

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

3 changes: 2 additions & 1 deletion prism.js
Original file line number Diff line number Diff line change
Expand Up @@ -582,7 +582,8 @@ Prism.languages.clike = {
Prism.languages.javascript = Prism.languages.extend('clike', {
'keyword': /\b(as|async|await|break|case|catch|class|const|continue|debugger|default|delete|do|else|enum|export|extends|false|finally|for|from|function|get|if|implements|import|in|instanceof|interface|let|new|null|of|package|private|protected|public|return|set|static|super|switch|this|throw|true|try|typeof|var|void|while|with|yield)\b/,
'number': /\b-?(0x[\dA-Fa-f]+|0b[01]+|0o[0-7]+|\d*\.?\d+([Ee][+-]?\d+)?|NaN|Infinity)\b/,
'function': /(?!\d)[a-z0-9_$]+(?=\()/i
// Allow for all non-ASCII characters (See http://stackoverflow.com/a/2008444)
'function': /[_$a-zA-Z\xA0-\uFFFF][_$a-zA-Z0-9\xA0-\uFFFF]*(?=\()/i
});

Prism.languages.insertBefore('javascript', 'keyword', {
Expand Down
9 changes: 6 additions & 3 deletions tests/languages/javascript/function_feature.test
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ foo_bar()
f42()
_()
$()
ಠ_ಠ()
Ƞȡ_҇()

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

Expand All @@ -11,10 +13,11 @@ $()
["function", "foo_bar"], ["punctuation", "("], ["punctuation", ")"],
["function", "f42"], ["punctuation", "("], ["punctuation", ")"],
["function", "_"], ["punctuation", "("], ["punctuation", ")"],
["function", "$"], ["punctuation", "("], ["punctuation", ")"]
["function", "$"], ["punctuation", "("], ["punctuation", ")"],
["function", "ಠ_ಠ"], ["punctuation", "("], ["punctuation", ")"],
["function", "Ƞȡ_҇"], ["punctuation", "("], ["punctuation", ")"]
]

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

Checks for functions.
Also checks that function starting with a number are not highlighted.
Checks for functions. Also checks for unicode characters in identifiers.

0 comments on commit 29e26dc

Please sign in to comment.