From 834fbbb36afcd18777a7d9d9fbc8a0920a622ac7 Mon Sep 17 00:00:00 2001 From: Martin Edenhofer Date: Fri, 9 Jan 2015 00:25:25 +0100 Subject: [PATCH] Improved html rework. --- .../app/lib/app_post/utils.js.coffee | 14 +++++++------- public/assets/tests/html-utils.js | 17 +++++++++++++++++ 2 files changed, 24 insertions(+), 7 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 cbf3c12ca..5f576a74f 100644 --- a/app/assets/javascripts/app/lib/app_post/utils.js.coffee +++ b/app/assets/javascripts/app/lib/app_post/utils.js.coffee @@ -82,12 +82,12 @@ class App.Utils @htmlRemoveTags: (html) -> # remove tags, keep content - html.find('div, span, p, li, ul, ol, a, b, u, i, form, strong, blockquote, textarea, h1, h2, h3, h4, h5, h6').replaceWith( -> + html.find('div, span, p, li, ul, ol, a, b, u, i, label, small, strong, strike, pre, code, center, blockquote, form, textarea, font, address, table, thead, tbody, tr, td, h1, h2, h3, h4, h5, h6').replaceWith( -> $(@).contents() ) # remove tags & content - html.find('div, span, p, li, ul, ol, a, b, u, i, form, strong, blockquote, textarea, h1, h2, h3, h4, h5, h6, br, hr, img, input').remove() + html.find('div, span, p, li, ul, ol, a, b, u, i, label, small, strong, strike, pre, code, center, blockquote, form, textarea, font, table, thead, tbody, tr, td, h1, h2, h3, h4, h5, h6, br, hr, img, input, select, button, style, applet, canvas, script, frame, iframe').remove() html @@ -98,12 +98,12 @@ class App.Utils @_removeAttributes( html ) # remove tags, keep content - html.find('li, ul, ol, a, b, u, i, strong, form, blockquote, textarea, h1, h2, h3, h4, h5, h6').replaceWith( -> + html.find('li, ul, ol, a, b, u, i, label, small, strong, strike, pre, code, center, blockquote, form, textarea, font, address, table, thead, tbody, tr, td, h1, h2, h3, h4, h5, h6').replaceWith( -> $(@).contents() ) # remove tags & content - html.find('li, ul, ol, a, b, u, i, strong, form, blockquote, textarea, h1, h2, h3, h4, h5, h6, hr, img, input').remove() + html.find('li, ul, ol, a, b, u, i, label, small, strong, strike, pre, code, center, blockquote, form, textarea, font, address, table, thead, tbody, tr, td, h1, h2, h3, h4, h5, h6, hr, img, input, select, button, style, applet, canvas, script, frame, iframe').remove() html @@ -114,7 +114,7 @@ class App.Utils @_removeAttributes( html ) # remove tags, keep content - html.find('a').replaceWith( -> + html.find('a, font').replaceWith( -> $(@).contents() ) @@ -138,12 +138,12 @@ class App.Utils ) # remove tags & content - html.find('hr, img, form, input').remove() + html.find('form, font, hr, img, input, select, button, style, applet, canvas, script, frame, iframe').remove() html @_removeAttributes: (html) -> - html.find('div, span, p, li, ul, ol, a, b, u, i, strong, blockquote, h1, h2, h3, h4, h5, h6') + html.find('div, span, p, li, ul, ol, a, b, u, i, label, small, strong, strike, pre, code, center, blockquote, h1, h2, h3, h4, h5, h6') .removeAttr( 'style' ) .removeAttr( 'class' ) .removeAttr( 'title' ) diff --git a/public/assets/tests/html-utils.js b/public/assets/tests/html-utils.js index fe7884b58..392e7febb 100644 --- a/public/assets/tests/html-utils.js +++ b/public/assets/tests/html-utils.js @@ -197,6 +197,11 @@ test( "htmlRemoveTags", function() { result = App.Utils.htmlRemoveRichtext( $(source) ) equal( result.html(), should, source ) + source = "
This is some text!
" + //should = "
This is some text!
" + should = "This is some text!" + result = App.Utils.htmlRemoveRichtext( $(source) ) + equal( result.html(), should, source ) }); // htmlRemoveRichtext @@ -264,6 +269,13 @@ test( "htmlRemoveRichtext", function() { result = App.Utils.htmlRemoveRichtext( $(source) ) equal( result.html(), should, source ) + source = "
This is some text!
" + //should = "
This is some text!
" + should = "This is some text!" + result = App.Utils.htmlRemoveRichtext( $(source) ) + equal( result.html(), should, source ) + + }); // htmlClanup @@ -317,6 +329,11 @@ test( "htmlClanup", function() { result = App.Utils.htmlRemoveRichtext( $(source) ) equal( result.html(), should, source ) + source = "
This is some text!
" + //should = "
This is some text!
" + should = "This is some text!" + result = App.Utils.htmlRemoveRichtext( $(source) ) + equal( result.html(), should, source ) });