From a3df7a5aad99a047973f1002aa75d8ea1be3ef57 Mon Sep 17 00:00:00 2001 From: Martin Edenhofer Date: Thu, 30 Jul 2015 12:15:13 +0200 Subject: [PATCH] Remove html comments also. --- .../javascripts/app/lib/app_post/utils.js.coffee | 13 +++++++++++++ public/assets/tests/html-utils.js | 4 ++-- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/app/assets/javascripts/app/lib/app_post/utils.js.coffee b/app/assets/javascripts/app/lib/app_post/utils.js.coffee index f008f1e90..a3096c1bc 100644 --- a/app/assets/javascripts/app/lib/app_post/utils.js.coffee +++ b/app/assets/javascripts/app/lib/app_post/utils.js.coffee @@ -114,6 +114,9 @@ class App.Utils # htmlOnlyWithRichtext = App.Utils.htmlRemoveRichtext( html ) @htmlRemoveRichtext: (html) -> + # remove comments + @_removeComments( html ) + # remove style and class @_removeAttributes( html ) @@ -130,6 +133,9 @@ class App.Utils # cleanHtmlWithRichText = App.Utils.htmlCleanup( html ) @htmlCleanup: (html) -> + # remove comments + @_removeComments( html ) + # remove style and class @_removeAttributes( html ) @@ -169,6 +175,13 @@ class App.Utils .removeAttr( 'title' ) html + @_removeComments: (html) -> + html.contents().each( -> + if @nodeType == 8 + $(@).remove() + ) + html + # signatureNeeded = App.Utils.signatureCheck( message, signature ) @signatureCheck: (message, signature) -> messageText = $( '
' + message + '
' ).text().trim() diff --git a/public/assets/tests/html-utils.js b/public/assets/tests/html-utils.js index 1e8ea4640..18e42afc1 100644 --- a/public/assets/tests/html-utils.js +++ b/public/assets/tests/html-utils.js @@ -256,7 +256,7 @@ test( "htmlRemoveTags", function() { // htmlRemoveRichtext test( "htmlRemoveRichtext", function() { - var source = "
test
" + var source = "
test
" var should = "test" var result = App.Utils.htmlRemoveRichtext( $(source) ) equal( result.html(), should, source ) @@ -330,7 +330,7 @@ test( "htmlRemoveRichtext", function() { // htmlCleanup test( "htmlCleanup", function() { - var source = "
test
" + var source = "
test
" var should = "test" var result = App.Utils.htmlCleanup( $(source) ) equal( result.html(), should, source )