From 9fac05d7c90d0abf52923c685016c63b3eef6029 Mon Sep 17 00:00:00 2001 From: Sungho Kim Date: Fri, 26 Jun 2015 18:17:59 +0900 Subject: [PATCH] collapse duplicated returns made by
and block element fixed #57 --- libs/to-mark/src/renderer.basic.js | 2 +- libs/to-mark/src/toMark.js | 6 ++++-- libs/to-mark/test/toMark.spec.js | 6 ++++++ 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/libs/to-mark/src/renderer.basic.js b/libs/to-mark/src/renderer.basic.js index 47f1930f2b..3def74ffcc 100644 --- a/libs/to-mark/src/renderer.basic.js +++ b/libs/to-mark/src/renderer.basic.js @@ -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) { diff --git a/libs/to-mark/src/toMark.js b/libs/to-mark/src/toMark.js index 5b98cec18a..8dc79aa704 100644 --- a/libs/to-mark/src/toMark.js +++ b/libs/to-mark/src/toMark.js @@ -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 @@ -72,6 +72,8 @@ function parse(runner, renderer) { * @return {string} result */ function finalize(text) { + //collapse duplicated returns made by
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; diff --git a/libs/to-mark/test/toMark.spec.js b/libs/to-mark/test/toMark.spec.js index 112f74aaa5..37f48cf0a0 100644 --- a/libs/to-mark/test/toMark.spec.js +++ b/libs/to-mark/test/toMark.spec.js @@ -38,4 +38,10 @@ describe('toMark', function() { expect(toMark('strike')).toEqual('~~strike~~'); }); + + it('collapse duplicated returns made by
and block element', function() { + expect(toMark('

text
text

text

')).toEqual('text \ntext\n\ntext'); + expect(toMark('

text
text  

text

')).toEqual('text \ntext\n\ntext'); + expect(toMark('

text


text

')).toEqual('text\n\n \ntext'); + }); });