PHP syntax highlighting for .html files in Brackets.io Editor

断了今生、忘了曾经 提交于 2020-02-04 13:34:12

问题


I work with a templating engine which is powered by .html template files. These templates also allow the use of PHP. Is it possible to enable PHP syntax highlighting for .html files?

Update: As of Sprint 39, Brackets now allows you to include a ".brackets.json" file in your project directory which lets you map file extensions to languages.

This will let you use php syntax highlighting within a html file.

{
    "language.fileExtensions": {
        "html": "php"
    }
}

回答1:


Update 2: As of Brackets 0.42, this is even simpler still:

  1. Open an .html file
  2. Change the status bar dropdown from HTML to PHP
  3. Open the dropdown again and click "Set as Default for .html Files"

Earlier update: You can now do this via a simple Brackets extension, without needing to modify the core code:

define(function (require, exports, module) {
    var LanguageManager = brackets.getModule("language/LanguageManager");
    var htmlLang = LanguageManager.getLanguage("html"),
        phpLang  = LanguageManager.getLanguage("php");
    htmlLang.removeFileExtension("html");
    phpLang.addFileExtension("html");
});
  1. Put this code in a file named main.js
  2. In Brackets, go to Help > Show Extensions Folder
  3. Create a new folder under user, and place the main.js file inside it
  4. Restart Brackets

Here's more info on writing Brackets extensions, if needed.


(old answer)

Unfortunately this is tricky in Brackets currently. Syntax highlighting is extensible in that you can assign new file extensions to a particular highlighting mode, but the ".html" extension is already in use by the plain-HTML highlighting mode.

Your best options are probably:

a) Pull Brackets from git and locally patch the languages.json file so that .html is interpreted as PHP instead. (You could do this in a regular installed build but it won't be fun, since that JSON file is baked into a giant minified blob). Running from a git copy isn't too hard though.

b) Rename all your files to reflect that they're not plain HTML. Brackets will automatically recognize ".phtml" for example, which seems like a more appropriate file extension anyway. (If there's some other extension that your templating system will use but Brackets doesn't recognize automatically, you can use this trick to register it as a PHP-type extension).



来源:https://stackoverflow.com/questions/21569932/php-syntax-highlighting-for-html-files-in-brackets-io-editor

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