diff --git a/CHANGES.md b/CHANGES.md
index dac7a056dc..0ddce501b4 100644
--- a/CHANGES.md
+++ b/CHANGES.md
@@ -20,6 +20,7 @@ Improvements:
- fix(parser): Look-ahead regex now work for end matches also (#2237) [Josh Goebel][]
- fix(parser): Better errors when a language is missing (#2236) [Josh Goebel][]
- fix(go): Fix escaped character literals (#2266) [David Benjamin][]
+- fix(objectivec): Fix various preprocessor highlighting issues (#2265) [David Benjamin][]
- fix(objectivec): Handle multibyte character literals (#2268) [David Benjamin][]
[Josh Goebel]: https://github.com/yyyc514
diff --git a/src/languages/cpp.js b/src/languages/cpp.js
index 29c33263b6..bec975080f 100644
--- a/src/languages/cpp.js
+++ b/src/languages/cpp.js
@@ -56,7 +56,7 @@ function(hljs) {
hljs.inherit(STRINGS, {className: 'meta-string'}),
{
className: 'meta-string',
- begin: /<[^\n>]*>/, end: /$/,
+ begin: /<.*?>/, end: /$/,
illegal: '\\n',
},
hljs.C_LINE_COMMENT_MODE,
diff --git a/src/languages/objectivec.js b/src/languages/objectivec.js
index c52c4ad659..1a4a9fe1cc 100644
--- a/src/languages/objectivec.js
+++ b/src/languages/objectivec.js
@@ -66,16 +66,24 @@ function(hljs) {
},
{
className: 'meta',
- begin: '#',
- end: '$',
+ begin: /#\s*[a-z]+\b/, end: /$/,
+ keywords: {
+ 'meta-keyword':
+ 'if else elif endif define undef warning error line ' +
+ 'pragma ifdef ifndef include'
+ },
contains: [
+ {
+ begin: /\\\n/, relevance: 0
+ },
+ hljs.inherit(hljs.QUOTE_STRING_MODE, {className: 'meta-string'}),
{
className: 'meta-string',
- variants: [
- { begin: '\"', end: '\"' },
- { begin: '<', end: '>' }
- ]
- }
+ begin: /<.*?>/, end: /$/,
+ illegal: '\\n',
+ },
+ hljs.C_LINE_COMMENT_MODE,
+ hljs.C_BLOCK_COMMENT_MODE
]
},
{
diff --git a/test/markup/cpp/preprocessor.expect.txt b/test/markup/cpp/preprocessor.expect.txt
index 62fff51bcc..2a7548ebc8 100644
--- a/test/markup/cpp/preprocessor.expect.txt
+++ b/test/markup/cpp/preprocessor.expect.txt
@@ -11,3 +11,9 @@
#define x(v) ((v))
# define x(v) ((v))
# define x(v) ((v))
+
+#if MACRO_WITH_STRING_ARG("hello \"world\"")
+#elif MULTI_LINE < \
+ EXPRESSION
+int bar;
+#endif
diff --git a/test/markup/cpp/preprocessor.txt b/test/markup/cpp/preprocessor.txt
index b1ad6a67ff..01372cbfcd 100644
--- a/test/markup/cpp/preprocessor.txt
+++ b/test/markup/cpp/preprocessor.txt
@@ -11,3 +11,9 @@ int foo(void)
#define x(v) ((v))
# define x(v) ((v))
# define x(v) ((v))
+
+#if MACRO_WITH_STRING_ARG("hello \"world\"")
+#elif MULTI_LINE /* comment */ < \
+ EXPRESSION
+int bar;
+#endif // comment
diff --git a/test/markup/objectivec/preprocessor.expect.txt b/test/markup/objectivec/preprocessor.expect.txt
new file mode 100644
index 0000000000..9002811ef6
--- /dev/null
+++ b/test/markup/objectivec/preprocessor.expect.txt
@@ -0,0 +1,19 @@
+#include <iostream>
+#define foo 1<<16
+
+#ifdef DEBUG
+TYPE1 foo(void)
+#else
+int foo(void)
+#endif
+{ }
+
+#define x(v) ((v))
+# define x(v) ((v))
+# define x(v) ((v))
+
+#if MACRO_WITH_STRING_ARG("hello \"world\"")
+#elif MULTI_LINE < \
+ EXPRESSION
+int bar;
+#endif
diff --git a/test/markup/objectivec/preprocessor.txt b/test/markup/objectivec/preprocessor.txt
new file mode 100644
index 0000000000..01372cbfcd
--- /dev/null
+++ b/test/markup/objectivec/preprocessor.txt
@@ -0,0 +1,19 @@
+#include
+#define foo 1<<16
+
+#ifdef DEBUG
+TYPE1 foo(void)
+#else
+int foo(void)
+#endif
+{ }
+
+#define x(v) ((v))
+# define x(v) ((v))
+# define x(v) ((v))
+
+#if MACRO_WITH_STRING_ARG("hello \"world\"")
+#elif MULTI_LINE /* comment */ < \
+ EXPRESSION
+int bar;
+#endif // comment