diff --git a/script.js b/script.js index d12f98d..65bfbc4 100644 --- a/script.js +++ b/script.js @@ -12,7 +12,7 @@ function looksLikeTable(data) { editor.addEventListener("paste", function(event) { var clipboard = event.clipboardData - var data = clipboard.getData('text/plain').trim() + var data = clipboard.getData('text/plain') if(looksLikeTable(data)) { event.preventDefault() @@ -20,10 +20,15 @@ editor.addEventListener("paste", function(event) { return } - var rows = data.split((/[\u0085\u2028\u2029]|\r\n?/g)).map(function(row) { - row = row.replace('\n', ' ') - return row.split("\t") - }) + var rows = data + .split(/[\u0085\u2028\u2029]|\r?\n/g) + .reduce(function (result, row) { + const re = /^[\t\n]*$/; + if (!re.test(row)) { + result.push(row.replace("\n", " ").split("\t")); + } + return result; + }, []); var colAlignments = []