Improved html rework.

This commit is contained in:
Martin Edenhofer 2015-01-09 00:25:25 +01:00
parent 6bb1522e29
commit 834fbbb36a
2 changed files with 24 additions and 7 deletions

View file

@ -82,12 +82,12 @@ class App.Utils
@htmlRemoveTags: (html) -> @htmlRemoveTags: (html) ->
# remove tags, keep content # 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() $(@).contents()
) )
# remove tags & content # 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 html
@ -98,12 +98,12 @@ class App.Utils
@_removeAttributes( html ) @_removeAttributes( html )
# remove tags, keep content # 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() $(@).contents()
) )
# remove tags & content # 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 html
@ -114,7 +114,7 @@ class App.Utils
@_removeAttributes( html ) @_removeAttributes( html )
# remove tags, keep content # remove tags, keep content
html.find('a').replaceWith( -> html.find('a, font').replaceWith( ->
$(@).contents() $(@).contents()
) )
@ -138,12 +138,12 @@ class App.Utils
) )
# remove tags & content # 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 html
@_removeAttributes: (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( 'style' )
.removeAttr( 'class' ) .removeAttr( 'class' )
.removeAttr( 'title' ) .removeAttr( 'title' )

View file

@ -197,6 +197,11 @@ test( "htmlRemoveTags", function() {
result = App.Utils.htmlRemoveRichtext( $(source) ) result = App.Utils.htmlRemoveRichtext( $(source) )
equal( result.html(), should, source ) equal( result.html(), should, source )
source = "<div><font size=\"3\" color=\"red\">This is some text!</font></div>"
//should = "<div>This is some text!</div>"
should = "This is some text!"
result = App.Utils.htmlRemoveRichtext( $(source) )
equal( result.html(), should, source )
}); });
// htmlRemoveRichtext // htmlRemoveRichtext
@ -264,6 +269,13 @@ test( "htmlRemoveRichtext", function() {
result = App.Utils.htmlRemoveRichtext( $(source) ) result = App.Utils.htmlRemoveRichtext( $(source) )
equal( result.html(), should, source ) equal( result.html(), should, source )
source = "<div><font size=\"3\" color=\"red\">This is some text!</font></div>"
//should = "<div>This is some text!</div>"
should = "This is some text!"
result = App.Utils.htmlRemoveRichtext( $(source) )
equal( result.html(), should, source )
}); });
// htmlClanup // htmlClanup
@ -317,6 +329,11 @@ test( "htmlClanup", function() {
result = App.Utils.htmlRemoveRichtext( $(source) ) result = App.Utils.htmlRemoveRichtext( $(source) )
equal( result.html(), should, source ) equal( result.html(), should, source )
source = "<div><font size=\"3\" color=\"red\">This is some text!</font></div>"
//should = "<div>This is some text!</div>"
should = "This is some text!"
result = App.Utils.htmlRemoveRichtext( $(source) )
equal( result.html(), should, source )
}); });