diff --git a/src/language-html/printer-htmlparser2.js b/src/language-html/printer-htmlparser2.js index 2b6232658..4ab42327b 100644 --- a/src/language-html/printer-htmlparser2.js +++ b/src/language-html/printer-htmlparser2.js @@ -188,7 +188,7 @@ function printOpeningTag(path, print, isVoid) { // Don't break self-closing elements with no attributes if (isVoid && !n.attributes.length) { - return concat(["<", n.name, ">"]); + return concat(["<", n.name, " />"]); } // Don't break up opening elements with a single long text attribute @@ -202,13 +202,10 @@ function printOpeningTag(path, print, isVoid) { concat([ "<", n.name, - concat([ - indent( - concat(path.map(attr => concat([line, print(attr)]), "attributes")) - ), - softline - ]), - ">" + indent( + concat(path.map(attr => concat([line, print(attr)]), "attributes")) + ), + isVoid ? concat([line, "/>"]) : concat([softline, ">"]) ]) ); } diff --git a/tests/html_attributes/__snapshots__/jsfmt.spec.js.snap b/tests/html_attributes/__snapshots__/jsfmt.spec.js.snap index 030640caf..9c99b6d46 100644 --- a/tests/html_attributes/__snapshots__/jsfmt.spec.js.snap +++ b/tests/html_attributes/__snapshots__/jsfmt.spec.js.snap @@ -62,9 +62,9 @@ and HTML5 Apps. It also documents Mozilla products, like Firefox OS."> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - - - + + +
@@ -77,7 +77,7 @@ and HTML5 Apps. It also documents Mozilla products, like Firefox OS."> content="The Mozilla Developer Network (MDN) provides information about Open Web technologies including HTML, CSS, and APIs for both Web sites and HTML5 Apps. It also documents Mozilla products, like Firefox OS." -> +/>
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-
+
`;
exports[`single-quotes.html - parse5-verify 1`] = `
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-
+
`;
diff --git a/tests/html_basics/__snapshots__/jsfmt.spec.js.snap b/tests/html_basics/__snapshots__/jsfmt.spec.js.snap
index 74d18c7b8..31cd3eeda 100644
--- a/tests/html_basics/__snapshots__/jsfmt.spec.js.snap
+++ b/tests/html_basics/__snapshots__/jsfmt.spec.js.snap
@@ -106,7 +106,7 @@ exports[`form.html - parse5-verify 1`] = `
id="exampleInputEmail1"
aria-describedby="emailHelp"
placeholder="Enter email"
- >
+ />
We'll never share your email with anyone else.
@@ -118,7 +118,7 @@ exports[`form.html - parse5-verify 1`] = `
class="form-control"
id="exampleInputPassword1"
placeholder="Password"
- >
+ />
- Hello world!
+ Hello world!
This is HTML5 Boilerplate.