From bf22cc55e17cfa83632cce733338b29ad6f1018e Mon Sep 17 00:00:00 2001 From: azivner Date: Fri, 25 Aug 2017 20:40:33 -0400 Subject: [PATCH] better handling of newlines which should hopefully eliminate new line duplication --- static/js/html2notecase.js | 8 +++++++- static/js/notecase2html.js | 6 +++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/static/js/html2notecase.js b/static/js/html2notecase.js index e2de65012..0241175cd 100644 --- a/static/js/html2notecase.js +++ b/static/js/html2notecase.js @@ -1,7 +1,11 @@ function html2notecase(contents, note) { + //console.log("'" + contents + "'"); + // remove any possible extra newlines which might be inserted - all relevant new lines should be only in
and

contents = contents.replace(/(?:\r\n|\r|\n)/, ''); + contents = contents.replace(/
<\/p>/g, '\n'); + contents = contents.replace(/


<\/p>/g, '\n'); contents = contents.replace(/
/g, '\n'); contents = contents.replace(/
/g, '\n'); contents = contents.replace(/<\/p>/g, '\n'); @@ -144,7 +148,9 @@ function html2notecase(contents, note) { } } - //console.log(contents); + contents = contents.trim(); + + //console.log('"' + contents + '"'); note.detail.note_text = contents; } \ No newline at end of file diff --git a/static/js/notecase2html.js b/static/js/notecase2html.js index 54e56c721..c4d66f9f7 100644 --- a/static/js/notecase2html.js +++ b/static/js/notecase2html.js @@ -43,7 +43,11 @@ function notecase2html(note) { } } - noteText = noteText.replace(/(?:\r\n|\r|\n)/g, '
'); + noteText = noteText.replace(/(?:\r\n|\r)/g, '\n'); + + noteText = noteText.replace(/(.+)\n/g, '

$1

'); + + noteText = noteText.replace(/\n/g, '


'); noteText = noteText.replace(/ /g, '  ');