RiFi2k / format-html-in-php

Basically this vscode extension uses all your standard configurations for html formatting, and your standard configurations for format on save, etc. It more or less works exactly how vscode should already work as it pertains to HTML in PHP files.
The Unlicense
33 stars 6 forks source link
formatter html php vscode vscode-extension

Format HTML in PHP

Formatting for the HTML code in PHP files.

This extension provides formatting for the HTML code in PHP files. This way this works is this extension runs right before the save action which triggers any other registered PHP formatting extensions so you are free to have one and this will not get in the way or block it.

Demo

Supported Features

There are multiple issues and Stackoverflow posts about not being able to format the HTML in PHP files and none of the solutions proposed anywhere really worked 100% so I decided to fix it.

Issues, Ideas, Feature Requests? Go ahead and add them. I'm down to help, add, or fix anything because I know this is badly needed for a lot of PHP / WordPress devs and was a major annoyance for me.

Feel free to have nested HTML in .php files now, it will format as you are expecting.


Using This Extension

Keybinding

CTRL + ALT + F

You can change this if desired through the standard Keyboard Shortcuts (File > Preferences > Keyboard Shortcuts) option screen the name is "Format HTML in PHP".

Context Menu

Within a PHP file you can right click and there is a menu option to Format HTML in PHP.

Format On Save

Turn on format on save either globally or scoped to PHP.

"editor.formatOnSave": false,
"[php]": {
  "editor.formatOnSave": true
}

HTML Settings

Here is the list of native vscode settings I pass to JS Beautify which control how your HTML will be formatted. You can change any of these to configure how the HTML will be formatted.

"editor.insertSpaces": true,
"editor.tabSize": 4,
"html.format.contentUnformatted": "pre,code,textarea",
"html.format.endWithNewline": false,
"html.format.extraLiners": "head, body, /html",
"html.format.indentHandlebars": false,
"html.format.indentInnerHtml": false,
"html.format.maxPreserveNewLines": null,
"html.format.preserveNewLines": true,
"html.format.wrapLineLength": 120,
"html.format.wrapAttributes": "auto",

Install

See the extension installation guide for details.


Release Notes

1.6.3

1.6.2

1.6.1

1.5.3

1.5.2

1.5.0

1.4.6

1.4.4

1.4.3

1.4.1

1.4.0

1.3.8

1.3.7

1.3.6

1.3.5

1.3.4

1.3.2

1.3.1

1.3.0

Being a better neighbor!

1.2.0

Major refactor.

1.1.1

Initial release