Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/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.
https://github.com/RiFi2k/format-html-in-php

formatter html php vscode vscode-extension

Last synced: about 2 months ago
JSON representation

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.

Awesome Lists containing this project

README

        

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](https://github.com/RiFi2k/format-html-in-php/blob/master/format-html-in-php.gif?raw=true)

**Supported Features**

- Uses VSCode configurations for HTML formatting
- Uses VSCode format on save setting
- Custom keybinding for anytime formatting
- Right click context menu option on PHP files
- Command Palette option for formatting

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](https://github.com/RiFi2k/format-html-in-php/issues). 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.

```json
"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.

```json
"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](https://code.visualstudio.com/docs/editor/extension-gallery) for details.

---

## Release Notes

### 1.6.3

- JS Beautify to stable 1.12.0

### 1.6.2

- JS Beautify to stable 1.10.3

### 1.6.1

- JS Beautify to stable 1.10.1

### 1.5.3

- JS Beautify to stable 1.9.0

### 1.5.2

- Documentation update about HTML settings - [#17](https://github.com/RiFi2k/format-html-in-php/issues/17)
- JS Beautify bump to latest beta

### 1.5.0

- Updating to the new JS Beautify version. If anyone notices any issues let me know!
- Upstream fixes [#14](https://github.com/RiFi2k/format-html-in-php/issues/14) - Don't format