Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
## Version 11.12.1

Grammars:

- fix(php) one-line comments end at the closing `?>` tag, not at the end of the line [Clark][]

Documentation:

- docs: switch the Sphinx docs theme from ReadTheDocs to Shibuya [Haowei Hsu][]
Expand All @@ -8,6 +12,7 @@ Documentation:
CONTRIBUTORS

[Haowei Hsu]: https://github.com/hwhsu1231
[Clark]: https://github.com/clark719664

## Version 11.12.0

Expand Down
21 changes: 13 additions & 8 deletions src/languages/php.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ export default function(hljs) {
scope: 'variable',
match: '\\$+' + IDENT_RE,
};
// One-line comments end at the closing tag as well as at the end of the
// line, so `// ... ?>` must not swallow the tag.
const LINE_COMMENT_END = /$|(?=\?>)/;
const C_LINE_COMMENT_MODE = hljs.COMMENT('//', LINE_COMMENT_END);
const HASH_COMMENT_MODE = hljs.COMMENT('#', LINE_COMMENT_END);
const PREPROCESSOR = {
scope: "meta",
variants: [
Expand Down Expand Up @@ -418,8 +423,8 @@ export default function(hljs) {
VARIABLE,
LEFT_AND_RIGHT_SIDE_OF_DOUBLE_COLON,
hljs.C_BLOCK_COMMENT_MODE,
hljs.C_LINE_COMMENT_MODE,
hljs.HASH_COMMENT_MODE,
C_LINE_COMMENT_MODE,
HASH_COMMENT_MODE,
STRING,
NUMBER,
CONSTRUCTOR_CALL,
Expand All @@ -444,8 +449,8 @@ export default function(hljs) {
NAMED_ARGUMENT,
LEFT_AND_RIGHT_SIDE_OF_DOUBLE_COLON,
hljs.C_BLOCK_COMMENT_MODE,
hljs.C_LINE_COMMENT_MODE,
hljs.HASH_COMMENT_MODE,
C_LINE_COMMENT_MODE,
HASH_COMMENT_MODE,
STRING,
NUMBER,
CONSTRUCTOR_CALL,
Expand Down Expand Up @@ -500,8 +505,8 @@ export default function(hljs) {
keywords: KEYWORDS,
contains: [
ATTRIBUTES,
hljs.HASH_COMMENT_MODE,
hljs.COMMENT('//', '$'),
HASH_COMMENT_MODE,
C_LINE_COMMENT_MODE,
hljs.COMMENT(
'/\\*',
'\\*/',
Expand Down Expand Up @@ -574,8 +579,8 @@ export default function(hljs) {
VARIABLE,
LEFT_AND_RIGHT_SIDE_OF_DOUBLE_COLON,
hljs.C_BLOCK_COMMENT_MODE,
hljs.C_LINE_COMMENT_MODE,
hljs.HASH_COMMENT_MODE,
C_LINE_COMMENT_MODE,
HASH_COMMENT_MODE,
STRING,
NUMBER
]
Expand Down
8 changes: 8 additions & 0 deletions test/markup/php-template/comment-closing-tag.expect.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<span class="language-xml"><span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">&quot;</span></span></span><span class="language-php"><span class="hljs-meta">&lt;?php</span> <span class="hljs-keyword">echo</span> <span class="hljs-title function_ invoke__">esc_attr</span>( <span class="hljs-variable">$class</span> ); <span class="hljs-comment">// phpcs:ignore </span><span class="hljs-meta">?&gt;</span></span><span class="language-xml"><span class="hljs-tag"><span class="hljs-string">&quot;</span>&gt;</span>
</span><span class="language-php"><span class="hljs-meta">&lt;?php</span> <span class="hljs-comment"># a hash comment </span><span class="hljs-meta">?&gt;</span></span><span class="language-xml">
<span class="hljs-tag">&lt;<span class="hljs-name">p</span>&gt;</span></span><span class="language-php"><span class="hljs-meta">&lt;?php</span> <span class="hljs-keyword">echo</span> <span class="hljs-number">1</span>; <span class="hljs-comment">// a &quot;quoted&quot; </span><span class="hljs-meta">?&gt;</span></span><span class="language-xml"> tail<span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>
</span><span class="language-php"><span class="hljs-meta">&lt;?php</span>
<span class="hljs-comment">// a comment with no closing tag on its line</span>
<span class="hljs-keyword">echo</span> <span class="hljs-number">2</span>;
<span class="hljs-meta">?&gt;</span></span><span class="language-xml">
</span>
7 changes: 7 additions & 0 deletions test/markup/php-template/comment-closing-tag.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<div class="<?php echo esc_attr( $class ); // phpcs:ignore ?>">
<?php # a hash comment ?>
<p><?php echo 1; // a "quoted" ?> tail</p>
<?php
// a comment with no closing tag on its line
echo 2;
?>