Skip to content

Commit

Permalink
Fix unquoted, tight, self-closing elements
Browse files Browse the repository at this point in the history
  • Loading branch information
wooorm committed Aug 31, 2021
1 parent 62fa2f0 commit bb0238d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
2 changes: 1 addition & 1 deletion lib/tree.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ export function element(ctx, node, index, parent) {
if (
!ctx.tightClose ||
last === '/' ||
(schema.space === 'svg' && last && last !== '"' && last !== "'")
(last && last !== '"' && last !== "'")
) {
parts.push(' ')
}
Expand Down
15 changes: 12 additions & 3 deletions test/element.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,24 @@ test('`element`', (t) => {
'should serialize voids with `/` in `closeSelfClosing` and `tightSelfClosing` mode'
)

// This works in a browser. The `/` is not part of the `[src]`.
t.deepEqual(
toHtml(h('input', {type: 'checkbox'}), {
preferUnquoted: true,
tightSelfClosing: true,
closeSelfClosing: true
}),
'<input type=checkbox />',
'should serialize voids with `/` in `closeSelfClosing` and `tightSelfClosing` mode, w/ space after an unquoted attribute (1)'
)

t.deepEqual(
toHtml(h('img', {src: 'index.jpg'}), {
preferUnquoted: true,
closeSelfClosing: true,
tightSelfClosing: true
}),
'<img src=index.jpg/>',
'should serialize voids with `/` in `closeSelfClosing` and `tightSelfClosing` mode, without space after an unquoted attribute'
'<img src=index.jpg />',
'should serialize voids with `/` in `closeSelfClosing` and `tightSelfClosing` mode, w/ space after an unquoted attribute (2)'
)

t.deepEqual(
Expand Down

0 comments on commit bb0238d

Please sign in to comment.