Skip to content

Commit

Permalink
collapse duplicated returns made by <br /> and block element fixed #57
Browse files Browse the repository at this point in the history
  • Loading branch information
Sungho Kim authored and seonim-ryu committed Feb 5, 2020
1 parent 357244b commit 9fac05d
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
2 changes: 1 addition & 1 deletion libs/to-mark/src/renderer.basic.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ var basicRenderer = Renderer.factory({
},

//Paragraphs
'P': function(node, subContent) {
'P, DIV': function(node, subContent) {
return subContent + '\n\n';
},
'LI P': function(node, subContent) {
Expand Down
6 changes: 4 additions & 2 deletions libs/to-mark/src/toMark.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ var DomRunner = require('./domRunner'),
basicRenderer = require('./renderer.basic'),
gfmRenderer = require('./renderer.gfm');

var FIND_FIRST_LAST_RETURNS_RX = /^[\n]+|[\n]+$/g;

var FIND_FIRST_LAST_RETURNS_RX = /^[\n]+|[\n]+$/g,
FIND_DUPLICATED_RETURNS_RX = /[ \xA0]+\n\n/g;
/**
* toMark
* @exports toMark
Expand Down Expand Up @@ -72,6 +72,8 @@ function parse(runner, renderer) {
* @return {string} result
*/
function finalize(text) {
//collapse duplicated returns made by <br /> and block element
text = text.replace(FIND_DUPLICATED_RETURNS_RX, '\n');
//remove first and last \n
text = text.replace(FIND_FIRST_LAST_RETURNS_RX, '');
return text;
Expand Down
6 changes: 6 additions & 0 deletions libs/to-mark/test/toMark.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,10 @@ describe('toMark', function() {

expect(toMark('<del>strike</del>')).toEqual('~~strike~~');
});

it('collapse duplicated returns made by <br /> and block element', function() {
expect(toMark('<p>text<br />text<br /></p><p>text</p>')).toEqual('text \ntext\n\ntext');
expect(toMark('<p>text<br />text &nbsp;<br /></p><p>text</p>')).toEqual('text \ntext\n\ntext');
expect(toMark('<p>text<br /></p><br /><p>text</p>')).toEqual('text\n\n \ntext');
});
});

0 comments on commit 9fac05d

Please sign in to comment.