highlightjs/highlight.js

(PHP Template) A single apostrophe ' breaks php-template highlighting

Open

#4,152 创建于 2024年10月24日

在 GitHub 查看
 (17 评论) (0 反应) (0 负责人)JavaScript (22,960 star) (3,497 fork)batch import
buggood first issuehelp welcomelanguage

描述

Describe the issue An apostrophe ' that exists on its own without being closed seems to break highlighting of everything that comes after it even if it's in a comment or escaped but only with the language php-template. With php it works fine as it should.

Funnily if anywhere later this ' is "closed" it works again.

Which language seems to have the issue? php-template

Are you using highlight or highlightAuto? Highlight, not auto.

Sample Code to Reproduce Code: See expected behaviour

Not highlighted:

<?php
// This won't be highlighted unless there is another 
// single apostrophe later.
?>
<p>Some HTML <?= '\code' ?></p>

image

Correctly highlighted:

<?php
// This won't be highlighted unless there is another 
// single apostrophe later.
?>
<p>Some HTML <?= '\'code' ?></p>

image

Expected behavior Github highlights the php bits:

<?php
// This won't be highlighted unless there is another 
// single apostrophe later.
?>
<p>Some HTML <?= '\code' ?></p>

I expect it to highlight the code correctly even if not every ' is closed. In a comment for instance, English words allow for shortcuts with ' for instance "don't" or "can't".

Additional observations
Its breaks only if the apostrophe is in PHP code (not HTML) and if it's not in a code block comment /* such as this, that won't cause any troubles */. It's always everything that comes after it that is broken not before so if half the file doesn't contain a ' and then suddenly a php part with a ' either in a // comment ' or in a string 'string \' with an apostrophe' the bottom half of the file is not highlighted.

贡献者指南