diff --git a/CHANGES.md b/CHANGES.md
index 82b956d9e0..68c33e95ba 100644
--- a/CHANGES.md
+++ b/CHANGES.md
@@ -45,7 +45,8 @@ Core Grammars:
- fix(swift) - Fixed syntax highlighting for class func/var declarations [guuido]
- fix(yaml) - Fixed wrong escaping behavior in single quoted strings [guuido]
- enh(nim) - Add `concept` and `defer` to list of Nim keywords [Jake Leahy]
-
+- fix(dart) - Added highlighting for class and function names [guuido]
+
New Grammars:
- added 3rd party TTCN-3 grammar to SUPPORTED_LANGUAGES [Osmocom][]
diff --git a/src/languages/dart.js b/src/languages/dart.js
index 32e4b43b2a..027cffffca 100644
--- a/src/languages/dart.js
+++ b/src/languages/dart.js
@@ -9,6 +9,9 @@ Category: scripting
/** @type LanguageFn */
export default function(hljs) {
+
+ const regex = hljs.regex;
+
const SUBST = {
className: 'subst',
variants: [ { begin: '\\$[A-Za-z0-9_]+' } ]
@@ -221,6 +224,28 @@ export default function(hljs) {
$pattern: /[A-Za-z][A-Za-z0-9_]*\??/
};
+ const CLASS_NAME_RE = regex.either(
+ /\b([A-Z]+[a-z0-9]+)+/,
+ // ends in caps
+ /\b([A-Z]+[a-z0-9]+)+[A-Z]+/,
+ );
+
+ const CLASS_REFERENCE = {
+ relevance: 0,
+ variants: [
+ {
+ match: CLASS_NAME_RE,
+ scope: "title.class"
+ }
+ ]
+ };
+
+ const FUNCTION_REFERENCE = {
+ relevance: 0,
+ match: /[a-z][A-Za-z0-9]*(?=\()/,
+ className: "title.function",
+ };
+
return {
name: 'Dart',
keywords: KEYWORDS,
@@ -257,6 +282,8 @@ export default function(hljs) {
hljs.UNDERSCORE_TITLE_MODE
]
},
+ CLASS_REFERENCE,
+ FUNCTION_REFERENCE,
NUMBER,
{
className: 'meta',
diff --git a/test/markup/dart/class.expect.txt b/test/markup/dart/class.expect.txt
new file mode 100644
index 0000000000..42f65cf132
--- /dev/null
+++ b/test/markup/dart/class.expect.txt
@@ -0,0 +1,10 @@
+class Person {
+ String name;
+ int age;
+
+ Person(this.name, this.age);
+
+ void introduce() {
+ print('My name is $name and I am $age years old.');
+ }
+}
\ No newline at end of file
diff --git a/test/markup/dart/class.txt b/test/markup/dart/class.txt
new file mode 100644
index 0000000000..7de4dff9fb
--- /dev/null
+++ b/test/markup/dart/class.txt
@@ -0,0 +1,10 @@
+class Person {
+ String name;
+ int age;
+
+ Person(this.name, this.age);
+
+ void introduce() {
+ print('My name is $name and I am $age years old.');
+ }
+}
\ No newline at end of file
diff --git a/test/markup/dart/function.expect.txt b/test/markup/dart/function.expect.txt
new file mode 100644
index 0000000000..f5e62e17f9
--- /dev/null
+++ b/test/markup/dart/function.expect.txt
@@ -0,0 +1,11 @@
+void greet(String name) {
+ print('Hello, $name!');
+}
+
+void dummy(Foo obj) {
+ return obj;
+}
+
+int add(int a, int b) {
+ return a + b;
+}
\ No newline at end of file
diff --git a/test/markup/dart/function.txt b/test/markup/dart/function.txt
new file mode 100644
index 0000000000..1ce5f9dd8a
--- /dev/null
+++ b/test/markup/dart/function.txt
@@ -0,0 +1,11 @@
+void greet(String name) {
+ print('Hello, $name!');
+}
+
+void dummy(Foo obj) {
+ return obj;
+}
+
+int add(int a, int b) {
+ return a + b;
+}
\ No newline at end of file