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) ->
# 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' )

View file

@ -197,6 +197,11 @@ test( "htmlRemoveTags", function() {
result = App.Utils.htmlRemoveRichtext( $(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
@ -264,6 +269,13 @@ test( "htmlRemoveRichtext", function() {
result = App.Utils.htmlRemoveRichtext( $(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
@ -317,6 +329,11 @@ test( "htmlClanup", function() {
result = App.Utils.htmlRemoveRichtext( $(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 )
});