Skip to content

Commit

Permalink
feat: 🎸 add option indentInnerHtml (#758)
Browse files Browse the repository at this point in the history
  • Loading branch information
shufo authored Aug 11, 2023
1 parent 4ace697 commit 47a8075
Show file tree
Hide file tree
Showing 9 changed files with 99 additions and 2 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,12 @@ You can also format programmatically with the same syntax using the [blade-forma
| `Blade Formatter: format Indent Size` | An indent size | 4 |
| `Blade Formatter: format Wrap Line Length` | The length of line wrap size | 120 |
| `Blade Formatter: format Wrap Attributes` | The way to wrap attributes. `[auto\|force\|force-aligned\|force-expand-multiline\|aligned-multiple\|preserve\|preserve-aligned]` | `auto` |
| `Blade Formatter: format No Multiple Empty Lines` | Collapses multiple blank lines into a single blank line. | false |
| `Blade Formatter: format use Tabs` | Use tab as indentation character | false |
| `Blade Formatter: format Sort Tailwind Css Classes` | Sort Tailwind CSS classes automatically | false |
| `Blade Formatter: format Sort HTML Attributes` | Sort HTML Attributes in the specified order. [`none` \| `alphabetical` \| [`code-guide`](https://codeguide.co/#attribute-order) \| [`idiomatic`](https://github.com/necolas/idiomatic-html#attribute-order) \| [`vuejs`](https://eslint.vuejs.org/rules/attributes-order.html)] | `none` |
| `Blade Formatter: format Indent Inner Html` | Indent `<head>` and `<body>` sections in html. | false |
| `Blade Formatter: format use Tabs` | Use tab as indentation character | false |
| `Blade Formatter: format Custom Html Attributes Order` | Comma separated custom HTML attributes order. e.g. `id, data-.+, class, name`. To enable this you must specify sort html attributes option as `custom`. You can use regex for attribute names. | `none` |
| `Blade Formatter: format No Multiple Empty Lines` | Collapses multiple blank lines into a single blank line. | false |
| `Blade Formatter: format No PHP Syntax Check` | Disable PHP Syntax check. Enabling this will suppress syntax error reporing. | "" |
| `Blade Formatter: Dont Show New Version Message` | If set to 'true', the new version message won't be shown anymore. | false |

Expand Down
5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,11 @@
"default": "",
"markdownDescription": "Comma separated custom HTML attributes order. e.g. `id, data-.+, class, name`. To enable this you must specify sort html attributes option as `custom`. You can use regex for attribute names."
},
"bladeFormatter.format.indentInnerHtml": {
"type": "boolean",
"default": false,
"markdownDescription": "Indent \\<head\\> and \\<body\\> tag sections in html"
},
"bladeFormatter.misc.dontShowNewVersionMessage": {
"type": "boolean",
"default": false,
Expand Down
1 change: 1 addition & 0 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ export function activate(context: ExtensionContext) {
extConfig.customHtmlAttributesOrder,
noMultipleEmptyLines: extConfig.noMultipleEmptyLines,
noPhpSyntaxCheck: extConfig.noPhpSyntaxCheck,
indentInnerHtml: extConfig.indentInnerHtml,
...runtimeConfig, // override all settings by runtime config
...tailwindConfig,
};
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"indentInnerHtml": true
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<html>

<head>
@section('header')
<title>
foo
</title>
@endsection
</head>

<body>
<button className="prettier-class" id="prettier-id" onClick={this.handleClick}>
Click Here
</button>
</body>

</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<html>
<head>
@section('header')
<title>
foo
</title>
@endsection
</head>
<body>
<button className="prettier-class" id="prettier-id" onClick={this.handleClick}>
Click Here
</button>
</body>
</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<html>

<head>
@section('header')
<title>
foo
</title>
@endsection
</head>

<body>
<button className="prettier-class" id="prettier-id" onClick={this.handleClick}>
Click Here
</button>
</body>

</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<html>
<head>
@section('header')
<title>
foo
</title>
@endsection
</head>
<body>
<button className="prettier-class" id="prettier-id" onClick={this.handleClick}>
Click Here
</button>
</body>
</html>
25 changes: 25 additions & 0 deletions src/test/suite/extension.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,31 @@ suite("Extension Test Suite", () => {
await config.update("customHtmlAttributesOrder", undefined, true);
});

test("Should format file with runtime config / indentInnerHtml", async function (this: any) {
this.timeout(20000);
await formatSameAsBladeFormatter(
"withConfig/indentInnerHtml/index.blade.php",
"withConfig/indentInnerHtml/formatted.index.blade.php",
);
});

test("Should format file without runtime config / indentInnerHtml", async function (this: any) {
this.timeout(20000);
const config = vscode.workspace.getConfiguration(
"bladeFormatter.format",
);
await config.update(
"indentInnerHtml",
true,
true,
);
await formatSameAsBladeFormatter(
"withoutConfig/indentInnerHtml/index.blade.php",
"withoutConfig/indentInnerHtml/formatted.index.blade.php",
);
await config.update("indentInnerHtml", undefined, true);
});

test("Format command exists in command list", async function () {
const commands = await vscode.commands.getCommands();
assert(commands.includes(ExtensionConstants.formatCommandKey));
Expand Down

0 comments on commit 47a8075

Please sign in to comment.