Skip to content

Commit 0dce005

Browse files
committed
render number & fix skip tag false
1 parent 35699e6 commit 0dce005

File tree

3 files changed

+28
-9
lines changed

3 files changed

+28
-9
lines changed

lib/posthtml-render.js

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,19 +35,18 @@ function postHTMLRender(tree, options) {
3535

3636
function html(tree) {
3737

38-
if (typeof tree === 'string') {
39-
return tree;
40-
}
41-
4238
var buf = '';
4339

4440
traverse([].concat(tree), function(node) {
4541
if (!node) return;
46-
if (typeof node === 'string') {
42+
if (typeof node === 'string' || typeof node === 'number') {
4743
buf += node;
48-
return buf;
44+
return;
45+
}
46+
if (typeof node.tag === 'boolean' && !node.tag) {
47+
typeof node.content !== 'object' && (buf += node.content);
48+
return node.content;
4949
}
50-
if (typeof node.tag === 'boolean' && !node.tag) return node.content;
5150
var tag = node.tag || 'div';
5251
if (singleTags[tag]) {
5352
buf += '<'+ tag + attrs(node.attrs);

posthtml-render.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/test.js

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,20 @@ describe('PostHTML-Render test', function() {
99
expect(render('Hello world!')).to.eql('Hello world!');
1010
});
1111

12+
it('string in content', function() {
13+
expect(render({ content: 'Hello world!' })).to.eql('<div>Hello world!</div>');
14+
expect(render({ content: ['Hello world!'] })).to.eql('<div>Hello world!</div>');
15+
});
16+
17+
it('number', function() {
18+
expect(render(555)).to.eql('555');
19+
});
20+
21+
it('number in content', function() {
22+
expect(render({ content: 555 })).to.eql('<div>555</div>');
23+
expect(render({ content: [555] })).to.eql('<div>555</div>');
24+
});
25+
1226
it('string node', function() {
1327
expect(render(['Hello world!'])).to.eql('Hello world!');
1428
});
@@ -17,10 +31,16 @@ describe('PostHTML-Render test', function() {
1731
expect(render()).to.eql('');
1832
});
1933

20-
it('tag false', function() {
34+
it('tag false return string', function() {
35+
expect(render({ tag: false, content: 'Test' })).to.eql('Test');
2136
expect(render({ tag: false, content: ['Test'] })).to.eql('Test');
2237
});
2338

39+
it('tag false return number', function() {
40+
expect(render({ tag: false, content: 555 })).to.eql('555');
41+
expect(render({ tag: false, content: [555] })).to.eql('555');
42+
});
43+
2444
it('tag empty', function() {
2545
expect(render({ content: ['Test'] })).to.eql('<div>Test</div>');
2646
});

0 commit comments

Comments
 (0)