From 32a144e427a37b9cc04e3d8654b04701a30a74c1 Mon Sep 17 00:00:00 2001 From: xxiaoxiong Date: Tue, 26 May 2026 16:49:04 +0800 Subject: [PATCH] fix(php-template): add line comment support to prevent quote chars from breaking highlighting A single apostrophe ' inside a // or # line comment inside a --- src/languages/php-template.js | 14 ++++++++++++++ test/markup/php-template/apostrophe.expect.txt | 9 +++++++++ test/markup/php-template/apostrophe.txt | 8 ++++++++ 3 files changed, 31 insertions(+) create mode 100644 test/markup/php-template/apostrophe.expect.txt create mode 100644 test/markup/php-template/apostrophe.txt diff --git a/src/languages/php-template.js b/src/languages/php-template.js index b26e75f835..5d71a7418c 100644 --- a/src/languages/php-template.js +++ b/src/languages/php-template.js @@ -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: '"', diff --git a/test/markup/php-template/apostrophe.expect.txt b/test/markup/php-template/apostrophe.expect.txt new file mode 100644 index 0000000000..373d361dce --- /dev/null +++ b/test/markup/php-template/apostrophe.expect.txt @@ -0,0 +1,9 @@ +<html> +<body> +<?php +// This won't be a problem anymore +echo "Hello!"; +?> +</body> +</html> + \ No newline at end of file diff --git a/test/markup/php-template/apostrophe.txt b/test/markup/php-template/apostrophe.txt new file mode 100644 index 0000000000..dee45014ba --- /dev/null +++ b/test/markup/php-template/apostrophe.txt @@ -0,0 +1,8 @@ + + + + +