Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,8 @@ function render(tree, options) {
}

result += html(node.content);
} else if (node._withoutClosingTag) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

_withoutClosingTag The name is not very suitable because tag means that there is an opening and closing element.

It seems more appropriate to me that the _closingElement

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Regarding semantics, element in HTML refers to the whole thing - an element has start/opening and end/closing tags.

I agree double negation through the use of without in the name is unnecessary, but if a name such as _closingTag creates confusion, maybe we could use something like _needsClosing or _shouldClose or something similar?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Regarding semantics, element in HTML refers to the whole thing - an element has start/opening and end/closing tags.

It is considered that if the element is single such as <hr> or <img> then it is the element if the element has a closing element then the tag is used

result += '>' + html(node.content);
} else {
result += '>' + html(node.content) + '</' + tag + '>';
}
Expand Down
18 changes: 18 additions & 0 deletions test/render.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,24 @@ describe('PostHTML Render', () => {

expect(render(fixture)).to.eql(expected);
});

it('_withoutClosingTag', () => {
const fixture = {
content: [
{
content: [
{
content: ['Test', {}]
}
]
}
],
_withoutClosingTag: true
};
const expected = '<div><div><div>Test<div></div></div></div>';

expect(render(fixture)).to.eql(expected);
});
});

describe('Tree', () => {
Expand Down