atom/language-php

HTML comments do not gray out nested PHP in .php files.

Closed this issue · 2 comments

Prerequisites

Description

In php files, html comments do not gray out php that is contained within them.

Steps to Reproduce

  1. Create a file with .php extension.
  2. Fill file with the following content:
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <!-- <div>
        <?php
            echo 'html comments do not gray out php code within them';
        ?>
    </div> -->
</body>
</html>

Expected behavior:

I expect the php nested within the html comment to be grayed out along with the rest of the comment.

Actual behavior:

The php nested within the html comment is syntax highlighted normally, as if it were not contained in a comment. (NOTE: The php is able to be commented out by regular php comments as expected, but it is unaffected by html comments.)
image

Reproduces how often:

This happens for all php nested within html comments.

Versions

Atom: 1.45.0
Electron: 4.2.7
Chrome: 69.0.3497.128
Node: 10.11.0

OS: Windows 10
Version : 1903
OS Build: 18362.778

Additional Information

This is intentional, because HTML comments do not deactivate PHP. For instance:

<!-- <?php echo 1 + 1; ?> -->

results in <!-- 2 --> when interpreted.

If you don't like it to be colored, you can add something like this to your File -> Stylesheet...

.syntax--comment.syntax--html .syntax--php [class^="syntax--"] {
  color: unset;
}

@Ingramz I see... after I posted this issue, I thought this might be the case. I think there also might be the case where php echoes a comment ending:

<!-- <div>
<?php 
echo "-->";
echo "I think this is no longer in a comment after process by php";
echo "<!--";
?>
</div> -->

Thanks for your syntax highlighting fix suggestion! I think I will use it :)

I am closing this issue because the functionality is intentional.