From 27bf64f6ce23679f37d010fd47da81a6c379f2eb Mon Sep 17 00:00:00 2001 From: Ika Date: Thu, 20 Sep 2018 00:04:43 +0800 Subject: [PATCH] feat(html): self-closing for void tags (#5116) XHTML compatibility. --- src/language-html/printer-htmlparser2.js | 13 +++---- .../__snapshots__/jsfmt.spec.js.snap | 18 +++++----- .../__snapshots__/jsfmt.spec.js.snap | 34 +++++++++---------- .../__snapshots__/jsfmt.spec.js.snap | 4 +-- .../__snapshots__/jsfmt.spec.js.snap | 18 +++++----- .../__snapshots__/jsfmt.spec.js.snap | 2 +- .../__snapshots__/jsfmt.spec.js.snap | 18 +++++----- 7 files changed, 52 insertions(+), 55 deletions(-) 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." -> +/>
String
String
String
@@ -187,9 +187,9 @@ exports[`boolean.html - parse5-verify 1`] = ` - - - + + +
`; @@ -197,14 +197,14 @@ exports[`boolean.html - parse5-verify 1`] = ` exports[`dobule-quotes.html - parse5-verify 1`] = ` John 'ShotGun' Nelson ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -John 'ShotGun' Nelson +John 'ShotGun' Nelson `; exports[`single-quotes.html - parse5-verify 1`] = ` John "ShotGun" Nelson ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -John "ShotGun" Nelson +John "ShotGun" Nelson `; 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" - > + />
@@ -151,7 +151,7 @@ exports[`form.html - parse5-verify 1`] = ` class="form-control-file" id="exampleInputFile" aria-describedby="fileHelp" - > + /> This is some placeholder block-level help text for the above input. It's a bit lighter and easily wraps to a new line. @@ -167,7 +167,7 @@ exports[`form.html - parse5-verify 1`] = ` id="optionsRadios1" value="option1" checked - > + /> Option one is this and that—be sure to include why it's great
@@ -179,7 +179,7 @@ exports[`form.html - parse5-verify 1`] = ` name="optionsRadios" id="optionsRadios2" value="option2" - > + /> Option two can be something else and selecting it will deselect option one @@ -192,14 +192,14 @@ exports[`form.html - parse5-verify 1`] = ` id="optionsRadios3" value="option3" disabled - > + /> Option three is disabled
@@ -230,8 +230,8 @@ exports[`hello-world.html - parse5-verify 1`] = ` - - + + Document @@ -319,20 +319,20 @@ exports[`html5-boilerplate.html - parse5-verify 1`] = ` - + - + + /> - - + + - - + + @@ -406,7 +406,7 @@ exports[`void-elements.html - parse5-verify 1`] = ` - + diff --git a/tests/html_case/__snapshots__/jsfmt.spec.js.snap b/tests/html_case/__snapshots__/jsfmt.spec.js.snap index e170300a9..622f08ada 100644 --- a/tests/html_case/__snapshots__/jsfmt.spec.js.snap +++ b/tests/html_case/__snapshots__/jsfmt.spec.js.snap @@ -23,11 +23,11 @@ exports[`case.html - parse5-verify 1`] = ` My tITlE - +

- Hello world!
+ Hello world!
This is HTML5 Boilerplate.