Skip to content
This repository was archived by the owner on Apr 22, 2020. It is now read-only.

Commit 76dbf79

Browse files
bug 69: preprocessor directives that end with a multiline comment still open break.
1 parent b830f28 commit 76dbf79

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

src/prettify.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -922,7 +922,14 @@ if (patternParts[2]) { console.log(uneval(patternParts)); }
922922
null, '"\'']);
923923
}
924924
if (options['hashComments']) {
925-
shortcutStylePatterns.push([PR_COMMENT, /^#[^\r\n]*/, null, '#']);
925+
if (options['cStyleComments']) {
926+
// Stop C preprocessor declarations at an unclosed open comment
927+
shortcutStylePatterns.push(
928+
[PR_COMMENT, /^#(?:[^\r\n\/]|\/(?!\*)|\/\*[^\r\n]*?\*\/)*/,
929+
null, '#']);
930+
} else {
931+
shortcutStylePatterns.push([PR_COMMENT, /^#[^\r\n]*/, null, '#']);
932+
}
926933
}
927934
if (options['cStyleComments']) {
928935
fallthroughStylePatterns.push([PR_COMMENT, /^\/\/[^\r\n]*/, null]);

tests/prettify_test.html

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,9 @@ <h1>C w/ language specified</h1>
115115
void main() {
116116
printf("%u", fib(10));
117117
}
118+
119+
#define ZERO 0 /* a
120+
multiline comment */
118121
</pre>
119122

120123
<h1>C++</h1>
@@ -1113,7 +1116,10 @@ <h1>CSS w/ language specified</h1>
11131116
'`END`KWDvoid`END`PLN main`END`PUN()`END`PLN `END`PUN{`END`PLN<br>' +
11141117
'&nbsp; printf`END`PUN(`END`STR"%u"`END`PUN,`END`PLN fib`END`PUN(`END' +
11151118
'`LIT10`END`PUN));`END`PLN<br>' +
1116-
'`END`PUN}`END'),
1119+
'`END`PUN}`END`PLN<br>' +
1120+
'<br>' +
1121+
'`END`COM#define ZERO 0 /* a<br>' +
1122+
'&nbsp; multiline comment */`END'),
11171123
Cpp: (
11181124
'`COM#include &lt;iostream&gt;`END`PLN<br>' +
11191125
'<br>' +

0 commit comments

Comments
 (0)