Skip to content

Commit a5194dc

Browse files
committed
normalizeLine for input to '\n'
fix issue #19 for windows(\r\n)/mac(\r)
1 parent 4812667 commit a5194dc

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

mdedit.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -434,6 +434,11 @@ function spliceString(str, i, remove, add){
434434
return str.slice(0,i) + add + str.slice(i+remove);
435435
}
436436

437+
438+
function normalizeLine(str){
439+
return str.replace(/\r(\n)?/g, '\n');
440+
}
441+
437442
var actions = {
438443
'newline': function(state, options){
439444
var s = state.start;
@@ -855,6 +860,7 @@ Editor.prototype.getText = function(){
855860
};
856861

857862
Editor.prototype.setText = function(val){
863+
val = normalizeLine(val);
858864
this.inner.textContent = val;
859865
};
860866

@@ -1085,6 +1091,7 @@ Editor.prototype.paste = function(evt){
10851091
evt.preventDefault();
10861092

10871093
var pasted = evt.clipboardData.getData('text/plain');
1094+
pasted = normalizeLine(pasted);
10881095

10891096
this.apply({
10901097
add: pasted,

0 commit comments

Comments
 (0)