PHP's HERE Doc (EOT) syntax highlighting discrepancy with forward slash on Sublime Text 3

雨燕双飞 提交于 2021-01-27 22:51:03

问题


I am unfamiliar with how Sublime Text 3 uses syntax highlighting, as in, if it purely relies on the theme or has it's built in standard that themes run off of but in my case, there's some syntax highlighting discrepancy with using PHP's HERE docs and forward slashes. Once a forward slash is present, it appears ST3 thinks all the following code is apart of that tag.

Is this something I can fix?

Forward slash syntax highlighting discrepancy

No forward slash and correct syntax highlighting


回答1:


Because your HEREDOC is called JAVASCRIPT, Sublime Text is trying to syntax highlight the contents as JavaScript.

But because you are including HTML (the <script>...</script> tag), it highlights it incorrectly (it seems to think it is a regular expression and thus doesn't find/expect the HEREDOC to end until (what it thinks is) the regex does.).

The fix is simply to change your code to name the HEREDOC as HTML instead:

<?php 
$inlineJS =
<<<HTML
    <script>
    $('ele').click(function(){
        // some code
    });
    </script>
HTML;
?>


来源:https://stackoverflow.com/questions/40124576/phps-here-doc-eot-syntax-highlighting-discrepancy-with-forward-slash-on-subli

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!