From a5194dc2c2a3d1f1a4938e1b1116f614342e56d9 Mon Sep 17 00:00:00 2001 From: SilverFox Date: Sun, 17 Apr 2016 23:55:30 +0800 Subject: [PATCH] normalizeLine for input to '\n' fix issue #19 for windows(\r\n)/mac(\r) --- mdedit.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/mdedit.js b/mdedit.js index de8d325..8f9be39 100644 --- a/mdedit.js +++ b/mdedit.js @@ -434,6 +434,11 @@ function spliceString(str, i, remove, add){ return str.slice(0,i) + add + str.slice(i+remove); } + +function normalizeLine(str){ + return str.replace(/\r(\n)?/g, '\n'); +} + var actions = { 'newline': function(state, options){ var s = state.start; @@ -855,6 +860,7 @@ Editor.prototype.getText = function(){ }; Editor.prototype.setText = function(val){ + val = normalizeLine(val); this.inner.textContent = val; }; @@ -1085,6 +1091,7 @@ Editor.prototype.paste = function(evt){ evt.preventDefault(); var pasted = evt.clipboardData.getData('text/plain'); + pasted = normalizeLine(pasted); this.apply({ add: pasted,