Skip to content

Option to preserve self-closing tags #2375

@tumatanquang

Description

@tumatanquang

Description

The change in issue #1478 caused self-closing tags to automatically add a space before the slash when formatted. However, this syntax is XHTML, and is not necessary in HTML5.
So I hope there will be an option to preserve self-closing tags when formatting HTML.

Input

The code looked like this before beautification:

<input type="text"/>
<br/>
<input type="number" />
<hr/>
<input type="email"/>

Expected Output

The code should have looked like this after beautification:

<input type="text"/>
<br/>
<input type="number" />
<hr/>
<input type="email"/>

Actual Output

The code actually looked like this after beautification:

<input type="text" />
<br />
<input type="number" />
<hr />
<input type="email" />

Steps to Reproduce

Environment

OS: Browser, CLI

Settings

{
  "indent_size": 4,
  "indent_char": " ",
  "indent_with_tabs": false,
  "eol": "\n",
  "end_with_newline": false,
  "editorconfig": false,
  "indent_level": 0,
  "preserve_newlines": true,
  "max_preserve_newlines": 0,
  "space_in_paren": false,
  "space_in_empty_paren": false,
  "jslint_happy": false,
  "space_after_anon_function": false,
  "space_after_named_function": false,
  "brace_style": "end-expand,preserve-inline",
  "unindent_chained_methods": false,
  "break_chained_methods": false,
  "keep_array_indentation": false,
  "unescape_strings": false,
  "wrap_line_length": 0,
  "e4x": false,
  "good_stuff": false,
  "comma_first": false,
  "operator_position": "preserve-newline",
  "indent_empty_lines": false,
  "eval_code": false,
  "space_before_conditional": false,
  "templating": [
    "auto"
  ],
  "css": {
    "indent_size": 4,
    "indent_char": "\t",
    "indent_with_tabs": true,
    "eol": "\n",
    "end_with_newline": false,
    "brace_style": "collapse",
    "selector_separator_newline": false,
    "newline_between_rules": false,
    "indent_empty_lines": false,
    "wrap_line_length": 0
  },
  "html": {
    "indent_size": 4,
    "indent_char": "\t",
    "indent_with_tabs": true,
    "eol": "\n",
    "end_with_newline": false,
    "preserve_newlines": true,
    "max_preserve_newlines": 0,
    "indent_inner_html": true,
    "brace_style": "end-expand",
    "indent_scripts": "normal",
    "wrap_line_length": 0,
    "wrap_attributes": "preserve-aligned",
    "wrap_attributes_min_attrs": -1,
    "extra_liners": [],
    "editorconfig": false,
    "indent_empty_lines": false,
    "templating": [
      "auto"
    ]
  }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions