Skip to content

Commit

Permalink
fix: newline in table breaks syntax (close #16)(#17)
Browse files Browse the repository at this point in the history
  • Loading branch information
kyuwoo-choi authored and seonim-ryu committed Feb 5, 2020
1 parent 157fb1d commit 05afbcb
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 0 deletions.
2 changes: 2 additions & 0 deletions libs/to-mark/src/renderer.gfm.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ var gfmRenderer = Renderer.factory(basicRenderer, {
return subContent;
},
'TR TD, TR TH': function(node, subContent) {
subContent = subContent.replace(/(\r\n)|(\r)|(\n)/g, '');

return ' ' + subContent + ' |';
},
'TD BR, TH BR': function() {
Expand Down
5 changes: 5 additions & 0 deletions libs/to-mark/test/renderer.gfm.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,11 @@ describe('gfmRenderer', function() {
expect(getMarkdownText('<table><tr><td></td></tr></table>', '', 4)).toEqual(' |');
expect(getMarkdownText('<table><tr><th></th></tr></table>', '', 4)).toEqual(' |');
});

it('should replace newline', function() {
expect(getMarkdownText('<table><tr><td>te\nxt</td></tr></table>', 'text', 4)).toEqual(' text |');
expect(getMarkdownText('<table><tr><th>te\nxt</th></tr></table>', 'text', 4)).toEqual(' text |');
});
});

describe('TD BR, TH BR', function() {
Expand Down
14 changes: 14 additions & 0 deletions libs/to-mark/test/tomark.gfm.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,20 @@ describe('toMark', function() {
expect(toMark(htmlStr)).toEqual('| text |');
});

it('single td containing newline', function() {
var htmlStr = [
'<table>',
'<tbody>',
'<tr>',
'<td>te\nxt</td>',
'</tr>',
'</tbody>',
'</table>'
].join('');

expect(toMark(htmlStr)).toEqual('| text |');
});

it('multiple td', function() {
var htmlStr = [
'<table>',
Expand Down

0 comments on commit 05afbcb

Please sign in to comment.