diff --git a/internal_packages/composer/spec/contenteditable-quoted-text-spec.cjsx b/internal_packages/composer/spec/contenteditable-quoted-text-spec.cjsx index 72b09db43..8c5177b95 100644 --- a/internal_packages/composer/spec/contenteditable-quoted-text-spec.cjsx +++ b/internal_packages/composer/spec/contenteditable-quoted-text-spec.cjsx @@ -11,7 +11,7 @@ ContenteditableComponent = require "../lib/contenteditable-component", describe "ContenteditableComponent", -> beforeEach -> @onChange = jasmine.createSpy('onChange') - @html = 'Test HTML

' + @html = 'Test HTML
' @component = ReactTestUtils.renderIntoDocument( ) diff --git a/spec-nylas/quoted-html-parser-spec.coffee b/spec-nylas/quoted-html-parser-spec.coffee index 0458e2e62..bd2690284 100644 --- a/spec-nylas/quoted-html-parser-spec.coffee +++ b/spec-nylas/quoted-html-parser-spec.coffee @@ -242,6 +242,16 @@ describe "QuotedHTMLParser", -> test = clean(QuotedHTMLParser.removeQuotedHTML(before)) expect(test).toEqual clean(after) + it 'removes all trailing
tags except one', -> + input0 = "hello world

foolololol
" + expect0 = "hello world
" + expect(QuotedHTMLParser.removeQuotedHTML(input0)).toEqual expect0 + + it 'preserves
tags in the middle and only chops off tail', -> + input0 = "hello

world

foolololol
" + expect0 = "hello

world
" + expect(QuotedHTMLParser.removeQuotedHTML(input0)).toEqual expect0 + # We have a little utility method that you can manually uncomment to diff --git a/src/services/quoted-html-parser.coffee b/src/services/quoted-html-parser.coffee index 76a1dedcd..c8925c3fc 100644 --- a/src/services/quoted-html-parser.coffee +++ b/src/services/quoted-html-parser.coffee @@ -36,6 +36,18 @@ class QuotedHTMLParser doc = @_parseHTML(html) quoteElements = @_findQuoteLikeElements(doc, options) DOMUtils.removeElements(quoteElements, options) + childNodes = doc.body.childNodes + + extraTailBrTags = [] + for i in [(childNodes.length - 1)..0] by -1 + curr = childNodes[i] + next = childNodes[i - 1] + if curr and curr.nodeName == 'BR' and next and next.nodeName == 'BR' + extraTailBrTags.push(curr) + else + break + + DOMUtils.removeElements(extraTailBrTags) return doc.children[0].innerHTML appendQuotedHTML: (htmlWithoutQuotes, originalHTML) ->