Skip welcome & menu and move to editor
Welcome to JS Bin
Load cached copy from
 
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width">
  <title>JS Bin</title>
</head>
  
<body>
</body>
</html>
 
// Two new lines before text content followed by three new lines and one explicit new line with <br>
var input = '\r\n<div>\r\ntext\r\nwith newlines\r\n<br>\r\n</div>\r\n';
console.log("String to parse: '" + input + "'");
// Current xlsx impl
var output = input
  // Remove new lines and spaces from start of content
  .replace(/^[\t\n\r ]+/, "")
  // Remove new lines and spaces from end of content
  .replace(/[\t\n\r ]+$/,"")
  // Replace remaining new lines and spaces with space
  .replace(/[\t\n\r ]+/g, " ")
  // Replace <br> tags with new lines
  .replace(/<\s*[bB][rR]\s*\/?>/g,"\n")
  // Strip HTML elements
  .replace(/<[^>]*>/g,"");
// This will result in ' text with newlines \n '
console.log("xlsx implementation output: '" + output + "'");
// modified impl
var outputMod = input
  .replace(/^[\t\n\r ]+/, "")
  .replace(/[\t\n\r ]+$/,"")
  // Added line which removes any white space characters after and before html tags
  .replace(/>\s+/g,">").replace(/\s+</g,"<")
  .replace(/[\t\n\r ]+/g, " ")
  .replace(/<\s*[bB][rR]\s*\/?>/g,"\n")
  .replace(/<[^>]*>/g,"");
// This will result in 'text with newlines\n', which seems more appropriate
console.log("Modified implementation output: '" + outputMod + "'");
Output 300px

This bin was created anonymously and its free preview time has expired (learn why). — Get a free unrestricted account

Dismiss x
public
Bin info
anonymouspro
0viewers