Skip to content

fix(php-template): add line comment support to prevent quote chars from breaking highlighting#4411

Open
xxiaoxiong wants to merge 1 commit into
highlightjs:mainfrom
xxiaoxiong:fix/php-template-apostrophe-comment-4152
Open

fix(php-template): add line comment support to prevent quote chars from breaking highlighting#4411
xxiaoxiong wants to merge 1 commit into
highlightjs:mainfrom
xxiaoxiong:fix/php-template-apostrophe-comment-4152

Conversation

@xxiaoxiong
Copy link
Copy Markdown

Fixes #4152

Why
A single apostrophe ' inside a // or # line comment inside a <?php block in a PHP template would be matched by the APOS_STRING_MODE rule before PHP's comment parser could consume it. This caused all subsequent highlighting in the PHP block to break.

Example that was broken:

<?php
// This won't be highlighted unless there is another
?>

Changes
Added // and # line comment blocks with skip: true to the contains array in php-template.js, positioned before the string mode rules so comments are consumed first.

Testing

  • // don't in comment no longer breaks highlighting
  • # don't in comment no longer breaks highlighting
  • /* block comments */ continue to work
  • Single-quoted strings continue to work normally
  • Double-quoted strings continue to work normally
  • Existing markup test (default) passes unchanged
  • New markup test (apostrophe) added for regression coverage

Surface area

  • Language / PHP Template
  • Bug fix

…om breaking highlighting

A single apostrophe ' inside a // or # line comment inside a <?php block
would be matched by the APOS_STRING_MODE rule before PHP's comment
parser could consume it, causing all subsequent highlighting to break.

Added // and # line comment blocks with skip:true before the string
mode rules in the php-template contains array, ensuring comments are
consumed first.

Fixes highlightjs#4152

Co-authored-by: xxiaoxiong <xxiaoxiong@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

1 participant