Skip to content

Commit 3b04103

Browse files
committed
Change style to prefer spacious self-closing tags
This switches the serialization style from `<x/>` to `<x />`, as the latter is more in line with popular JSX use. The former behavior can be used by passing `tightSelfClosing: true`.
1 parent 1a95c30 commit 3b04103

File tree

3 files changed

+19
-19
lines changed

3 files changed

+19
-19
lines changed

lib/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
* Preferred quote to use around attribute values.
2323
* @property {boolean} [quoteSmart=false]
2424
* Use the other quote if that results in less bytes.
25-
* @property {boolean} [tightSelfClosing=true]
25+
* @property {boolean} [tightSelfClosing=false]
2626
* Do not use an extra space when closing self-closing elements: `<img/>`
2727
* instead of `<img />`.
2828
*/
@@ -366,7 +366,7 @@ export function mdxJsxFromMarkdown() {
366366
* @returns {ToMarkdownExtension}
367367
*/
368368
export function mdxJsxToMarkdown(options = {}) {
369-
const {quote = '"', quoteSmart, tightSelfClosing = true} = options
369+
const {quote = '"', quoteSmart, tightSelfClosing} = options
370370
const alternative = quote === '"' ? "'" : '"'
371371

372372
if (quote !== '"' && quote !== "'") {

readme.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ console.log(out)
200200
* a list
201201
</Box>
202202

203-
<MyComponent {...props}/>
203+
<MyComponent {...props} />
204204

205205
<abbr title="Hypertext Markup Language">HTML</abbr> is a lovely language.
206206
```
@@ -245,7 +245,7 @@ Use the other quote if that results in less bytes (`boolean`, default: `false`).
245245
###### `options.tightSelfClosing`
246246

247247
Do not use an extra space when closing self-closing elements: `<img/>` instead
248-
of `<img />` (`boolean`, default: `true`).
248+
of `<img />` (`boolean`, default: `false`).
249249

250250
## Syntax tree
251251

test.js

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1485,7 +1485,7 @@ test('mdast -> markdown', (t) => {
14851485
{type: 'mdxJsxFlowElement', name: 'x'},
14861486
{extensions: [mdxJsxToMarkdown()]}
14871487
),
1488-
'<x/>\n',
1488+
'<x />\n',
14891489
'should serialize flow jsx w/ `name` w/o `attributes`, `children`'
14901490
)
14911491

@@ -1541,7 +1541,7 @@ test('mdast -> markdown', (t) => {
15411541
},
15421542
{extensions: [mdxJsxToMarkdown()]}
15431543
),
1544-
'<x {y}/>\n',
1544+
'<x {y} />\n',
15451545
'should serialize flow jsx w/ `name`, `attributes` w/o `children`'
15461546
)
15471547

@@ -1586,7 +1586,7 @@ test('mdast -> markdown', (t) => {
15861586
},
15871587
{extensions: [mdxJsxToMarkdown()]}
15881588
),
1589-
'<x {...{y: "z"}}/>\n',
1589+
'<x {...{y: "z"}} />\n',
15901590
'should serialize expression attributes'
15911591
)
15921592

@@ -1602,7 +1602,7 @@ test('mdast -> markdown', (t) => {
16021602
},
16031603
{extensions: [mdxJsxToMarkdown()]}
16041604
),
1605-
'<x {}/>\n',
1605+
'<x {} />\n',
16061606
'should serialize expression attributes w/o `value`'
16071607
)
16081608

@@ -1634,7 +1634,7 @@ test('mdast -> markdown', (t) => {
16341634
},
16351635
{extensions: [mdxJsxToMarkdown()]}
16361636
),
1637-
'<x y/>\n',
1637+
'<x y />\n',
16381638
'should serialize boolean attributes'
16391639
)
16401640

@@ -1648,7 +1648,7 @@ test('mdast -> markdown', (t) => {
16481648
},
16491649
{extensions: [mdxJsxToMarkdown()]}
16501650
),
1651-
'<x y="z"/>\n',
1651+
'<x y="z" />\n',
16521652
'should serialize value attributes'
16531653
)
16541654

@@ -1668,7 +1668,7 @@ test('mdast -> markdown', (t) => {
16681668
},
16691669
{extensions: [mdxJsxToMarkdown()]}
16701670
),
1671-
'<x y={z}/>\n',
1671+
'<x y={z} />\n',
16721672
'should serialize value expression attributes'
16731673
)
16741674

@@ -1688,7 +1688,7 @@ test('mdast -> markdown', (t) => {
16881688
},
16891689
{extensions: [mdxJsxToMarkdown()]}
16901690
),
1691-
'<x y={}/>\n',
1691+
'<x y={} />\n',
16921692
'should serialize value expression attributes w/o `value`'
16931693
)
16941694

@@ -1705,7 +1705,7 @@ test('mdast -> markdown', (t) => {
17051705
{type: 'mdxJsxTextElement', name: 'x'},
17061706
{extensions: [mdxJsxToMarkdown()]}
17071707
),
1708-
'<x/>\n',
1708+
'<x />\n',
17091709
'should serialize text jsx w/ `name` w/o `attributes`, `children`'
17101710
)
17111711

@@ -1736,7 +1736,7 @@ test('mdast -> markdown', (t) => {
17361736
},
17371737
{extensions: [mdxJsxToMarkdown()]}
17381738
),
1739-
'<x y="z" a/>\n',
1739+
'<x y="z" a />\n',
17401740
'should serialize text jsx w/ attributes'
17411741
)
17421742

@@ -1846,7 +1846,7 @@ test('mdast -> markdown', (t) => {
18461846
},
18471847
{extensions: [mdxJsxToMarkdown({quote: "'"})]}
18481848
),
1849-
"<x y='z'/>\n",
1849+
"<x y='z' />\n",
18501850
'should support `options.quote` to quote attribute values'
18511851
)
18521852

@@ -1877,7 +1877,7 @@ test('mdast -> markdown', (t) => {
18771877
},
18781878
{extensions: [mdxJsxToMarkdown({quoteSmart: true})]}
18791879
),
1880-
'<x y="z"/>\n',
1880+
'<x y="z" />\n',
18811881
'should support `options.quoteSmart`: prefer `quote` w/o quotes'
18821882
)
18831883

@@ -1891,7 +1891,7 @@ test('mdast -> markdown', (t) => {
18911891
},
18921892
{extensions: [mdxJsxToMarkdown({quoteSmart: true})]}
18931893
),
1894-
'<x y="z&#x22;a\'b"/>\n',
1894+
'<x y="z&#x22;a\'b" />\n',
18951895
'should support `options.quoteSmart`: prefer `quote` w/ equal quotes'
18961896
)
18971897

@@ -1905,7 +1905,7 @@ test('mdast -> markdown', (t) => {
19051905
},
19061906
{extensions: [mdxJsxToMarkdown({quoteSmart: true})]}
19071907
),
1908-
'<x y=\'z"a&#x27;b"c\'/>\n',
1908+
'<x y=\'z"a&#x27;b"c\' />\n',
19091909
'should support `options.quoteSmart`: use alternative w/ more preferred quotes'
19101910
)
19111911

@@ -1919,7 +1919,7 @@ test('mdast -> markdown', (t) => {
19191919
},
19201920
{extensions: [mdxJsxToMarkdown({quoteSmart: true})]}
19211921
),
1922-
'<x y="z&#x22;a\'b\'c"/>\n',
1922+
'<x y="z&#x22;a\'b\'c" />\n',
19231923
'should support `options.quoteSmart`: use quote w/ more alternative quotes'
19241924
)
19251925

0 commit comments

Comments
 (0)