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
14 changes: 14 additions & 0 deletions src/languages/php-template.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,20 @@ export default function(hljs) {
end: '\\*/',
skip: true
},
// Line comments must appear before string modes to prevent a quote
// character inside a // or # comment from being matched as a string
// delimiter, which would break highlighting for the rest of the block.
// https://github.com/highlightjs/highlight.js/issues/4152
{
begin: /\/\//,
end: /$/,
skip: true
},
{
begin: /#/,
end: /$/,
skip: true
},
{
begin: 'b"',
end: '"',
Expand Down
9 changes: 9 additions & 0 deletions test/markup/php-template/apostrophe.expect.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<span class="language-xml"><span class="hljs-tag">&lt;<span class="hljs-name">html</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">body</span>&gt;</span>
</span><span class="language-php"><span class="hljs-meta">&lt;?php</span>
<span class="hljs-comment">// This won&#x27;t be a problem anymore</span>
<span class="hljs-keyword">echo</span> <span class="hljs-string">&quot;Hello!&quot;</span>;
<span class="hljs-meta">?&gt;</span></span><span class="language-xml">
<span class="hljs-tag">&lt;/<span class="hljs-name">body</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">html</span>&gt;</span>
</span>
8 changes: 8 additions & 0 deletions test/markup/php-template/apostrophe.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<html>
<body>
<?php
// This won't be a problem anymore
echo "Hello!";
?>
</body>
</html>