diff --git a/bits/22_xmlutils.js b/bits/22_xmlutils.js index 03c382b..f057c16 100644 --- a/bits/22_xmlutils.js +++ b/bits/22_xmlutils.js @@ -164,7 +164,7 @@ var matchtag = (function() { })(); function htmldecode(str/*:string*/)/*:string*/ { - return str.trim().replace(/\s+/g, " ").replace(/<\s*[bB][rR]\s*\/?/g,"\n").replace(/<[^>]*>/g,"").replace(/ /g, " "); + return str.trim().replace(/\s+/g, " ").replace(/<\s*[bB][rR]\s*\/?>/g,"\n").replace(/<[^>]*>/g,"").replace(/ /g, " "); } var vtregex = (function(){ var vt_cache = {}; diff --git a/test.js b/test.js index 4f7f64c..79cfde5 100644 --- a/test.js +++ b/test.js @@ -1861,6 +1861,11 @@ describe('HTML', function() { (domtest ? describe : describe.skip)('input DOM', function() { it('should interpret values by default', function() { plaintext_test(X.utils.table_to_book(get_dom_element(html_str)), false, true); }); it('should generate strings if raw option is passed', function() { plaintext_test(X.utils.table_to_book(get_dom_element(html_str), {raw:true}), true, true); }); + it('should handle newlines correctly', function() { + var table = get_dom_element("
foo
bar
baz
"); + var wb = X.utils.table_to_book(table) + assert.equal(get_cell(wb.Sheets.Sheet1, "A1").v, "foo\nbar"); + }); }); }); diff --git a/tests/core.js b/tests/core.js index 4f7f64c..2f665f4 100644 --- a/tests/core.js +++ b/tests/core.js @@ -1861,6 +1861,12 @@ describe('HTML', function() { (domtest ? describe : describe.skip)('input DOM', function() { it('should interpret values by default', function() { plaintext_test(X.utils.table_to_book(get_dom_element(html_str)), false, true); }); it('should generate strings if raw option is passed', function() { plaintext_test(X.utils.table_to_book(get_dom_element(html_str), {raw:true}), true, true); }); + it('should handle newlines correctly', function() { + var table = document.createElement('table'); + table.innerHTML = "foo
barbaz"; + var wb = X.utils.table_to_book(table) + assert.equal(get_cell(wb.Sheets.Sheet1, "A1").v, "foo\nbar"); + }); }); }); diff --git a/xlsx.flow.js b/xlsx.flow.js index 75d2e22..7a2a44f 100644 --- a/xlsx.flow.js +++ b/xlsx.flow.js @@ -2174,7 +2174,7 @@ var matchtag = (function() { })(); function htmldecode(str/*:string*/)/*:string*/ { - return str.trim().replace(/\s+/g, " ").replace(/<\s*[bB][rR]\s*\/?/g,"\n").replace(/<[^>]*>/g,"").replace(/ /g, " "); + return str.trim().replace(/\s+/g, " ").replace(/<\s*[bB][rR]\s*\/?>/g,"\n").replace(/<[^>]*>/g,"").replace(/ /g, " "); } var vtregex = (function(){ var vt_cache = {}; diff --git a/xlsx.js b/xlsx.js index 5adc3c7..475215e 100644 --- a/xlsx.js +++ b/xlsx.js @@ -2102,7 +2102,7 @@ var matchtag = (function() { })(); function htmldecode(str) { - return str.trim().replace(/\s+/g, " ").replace(/<\s*[bB][rR]\s*\/?/g,"\n").replace(/<[^>]*>/g,"").replace(/ /g, " "); + return str.trim().replace(/\s+/g, " ").replace(/<\s*[bB][rR]\s*\/?>/g,"\n").replace(/<[^>]*>/g,"").replace(/ /g, " "); } var vtregex = (function(){ var vt_cache = {};