Skip to content

Commit

Permalink
C#: More generic class-name highlighting. Fix #1365
Browse files Browse the repository at this point in the history
  • Loading branch information
Golmote committed Mar 24, 2018
1 parent 4a14d20 commit a6837d2
Show file tree
Hide file tree
Showing 5 changed files with 125 additions and 49 deletions.
12 changes: 11 additions & 1 deletion components/prism-csharp.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,17 @@ Prism.languages.csharp = Prism.languages.extend('clike', {
'number': /\b0x[\da-f]+\b|(?:\b\d+\.?\d*|\B\.\d+)f?/i
});

Prism.languages.insertBefore('csharp', 'keyword', {
if (Prism.util.type(Prism.languages.csharp['class-name']) !== 'Array') {
Prism.languages.csharp['class-name'] = [Prism.languages.csharp['class-name']];
}
Prism.languages.csharp['class-name'].push({
pattern: /\b[A-Z]\w*(?:\.\w+)*\b(?!\()/,
inside: {
punctuation: /\./
}
});

Prism.languages.insertBefore('csharp', 'class-name', {
'generic-method': {
pattern: /[a-z0-9_]+\s*<[^>\r\n]+?>\s*(?=\()/i,
alias: 'function',
Expand Down
2 changes: 1 addition & 1 deletion components/prism-csharp.min.js

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

100 changes: 53 additions & 47 deletions tests/languages/csharp+aspnet/directive_feature.test
Original file line number Diff line number Diff line change
Expand Up @@ -10,59 +10,65 @@
[
["directive tag", [
["directive tag", "<%:"],
" Page",
["punctuation", "."],
"Title ",
["class-name", [
"Page",
["punctuation", "."],
"Title"
]],
["directive tag", "%>"]
]],

["directive tag", [
["directive tag", "<%#:"],
"Item",
["punctuation", "."],
"ProductID",
["directive tag", "%>"]
]],
["directive tag", "<%#:"],
["class-name", [
"Item",
["punctuation", "."],
"ProductID"
]],
["directive tag", "%>"]
]],

["tag", [
["tag", [
["punctuation", "<"],
"a"
]],
["attr-name", [
"href"
]],
["attr-value", [
["punctuation", "="],
["punctuation", "\""],
"ProductDetails.aspx?productID=",
["directive tag", [
["directive tag", "<%#:"],
"Item",
["punctuation", "."],
"ProductID",
["directive tag", "%>"]
]],
["punctuation", "\""]
]],
["punctuation", ">"]
]],
["tag", [
["tag", [
["punctuation", "<"],
"a"
]],
["attr-name", [
"href"
]],
["attr-value", [
["punctuation", "="],
["punctuation", "\""],
"ProductDetails.aspx?productID=",
["directive tag", [
["directive tag", "<%#:"],
["class-name", [
"Item",
["punctuation", "."],
"ProductID"
]],
["directive tag", "%>"]
]],
["punctuation", "\""]
]],
["punctuation", ">"]
]],

["directive tag", [
["directive tag", "<%"],
["keyword", "if"],
["punctuation", "("],
"foo",
["punctuation", ")"],
["punctuation", "{"],
["directive tag", "%>"]
]],
"\r\n\tfoobar\r\n",
["directive tag", [
["directive tag", "<%"],
["punctuation", "}"],
["directive tag", "%>"]
]]
["directive tag", [
["directive tag", "<%"],
["keyword", "if"],
["punctuation", "("],
"foo",
["punctuation", ")"],
["punctuation", "{"],
["directive tag", "%>"]
]],
"\r\n\tfoobar\r\n",
["directive tag", [
["directive tag", "<%"],
["punctuation", "}"],
["directive tag", "%>"]
]]
]

----------------------------------------------------
Expand Down
21 changes: 21 additions & 0 deletions tests/languages/csharp/class-name_feature.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
class Foo
interface BarBaz
Foo.Barbaz

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

[
["keyword", "class"],
["class-name", ["Foo"]],
["keyword", "interface"],
["class-name", ["BarBaz"]],
["class-name", [
"Foo",
["punctuation", "."],
"Barbaz"
]]
]

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

Checks for class names.
39 changes: 39 additions & 0 deletions tests/languages/csharp/issue1365.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
interface ILogger {
void Init(SomeClass file);
void LogInfo(string message);
}
public class SomeClass : BaseClass {}

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

[
["keyword", "interface"],
["class-name", ["ILogger"]],
["punctuation", "{"],
["keyword", "void"],
["function", "Init"],
["punctuation", "("],
["class-name", ["SomeClass"]],
" file",
["punctuation", ")"],
["punctuation", ";"],
["keyword", "void"],
["function", "LogInfo"],
["punctuation", "("],
["keyword", "string"],
" message",
["punctuation", ")"],
["punctuation", ";"],
["punctuation", "}"],
["keyword", "public"],
["keyword", "class"],
["class-name", ["SomeClass"]],
["punctuation", ":"],
["class-name", ["BaseClass"]],
["punctuation", "{"],
["punctuation", "}"]
]

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

Checks for class names. See #1365

0 comments on commit a6837d2

Please sign in to comment.