##// END OF EJS Templates
Remove style tags from html body (#15716)....
Jean-Philippe Lang -
r13933:e911ce7cb41c
parent child
Show More
@@ -23,7 +23,8 module Redmine
23
23
24 class_attribute :tags
24 class_attribute :tags
25 self.tags = {
25 self.tags = {
26 'br' => {:post => "\n"}
26 'br' => {:post => "\n"},
27 'style' => ''
27 }
28 }
28
29
29 def self.to_text(html)
30 def self.to_text(html)
@@ -44,9 +45,16 module Redmine
44
45
45 def scrub(node)
46 def scrub(node)
46 formatting = @tags_to_text[node.name]
47 formatting = @tags_to_text[node.name]
47 return CONTINUE unless formatting
48 case formatting
48 node.add_next_sibling Nokogiri::XML::Text.new("#{formatting[:pre]}#{node.content}#{formatting[:post]}", node.document)
49 when Hash
49 node.remove
50 node.add_next_sibling Nokogiri::XML::Text.new("#{formatting[:pre]}#{node.content}#{formatting[:post]}", node.document)
51 node.remove
52 when String
53 node.add_next_sibling Nokogiri::XML::Text.new(formatting, node.document)
54 node.remove
55 else
56 CONTINUE
57 end
50 end
58 end
51 end
59 end
52 end
60 end
@@ -32,7 +32,8 module Redmine
32 'h3' => {:pre => "\n\n### ", :post => "\n\n"},
32 'h3' => {:pre => "\n\n### ", :post => "\n\n"},
33 'h4' => {:pre => "\n\n#### ", :post => "\n\n"},
33 'h4' => {:pre => "\n\n#### ", :post => "\n\n"},
34 'h5' => {:pre => "\n\n##### ", :post => "\n\n"},
34 'h5' => {:pre => "\n\n##### ", :post => "\n\n"},
35 'h6' => {:pre => "\n\n###### ", :post => "\n\n"}
35 'h6' => {:pre => "\n\n###### ", :post => "\n\n"},
36 'style' => ''
36 }
37 }
37 end
38 end
38 end
39 end
@@ -33,7 +33,8 module Redmine
33 'h3' => {:pre => "\n\nh3. ", :post => "\n\n"},
33 'h3' => {:pre => "\n\nh3. ", :post => "\n\n"},
34 'h4' => {:pre => "\n\nh4. ", :post => "\n\n"},
34 'h4' => {:pre => "\n\nh4. ", :post => "\n\n"},
35 'h5' => {:pre => "\n\nh5. ", :post => "\n\n"},
35 'h5' => {:pre => "\n\nh5. ", :post => "\n\n"},
36 'h6' => {:pre => "\n\nh6. ", :post => "\n\n"}
36 'h6' => {:pre => "\n\nh6. ", :post => "\n\n"},
37 'style' => ''
37 }
38 }
38 end
39 end
39 end
40 end
@@ -27,4 +27,9 class Redmine::WikiFormatting::HtmlParserTest < ActiveSupport::TestCase
27 assert_equal "A html snippet with\na new line.",
27 assert_equal "A html snippet with\na new line.",
28 @parser.to_text('<p>A html snippet with<br>a new line.</p>')
28 @parser.to_text('<p>A html snippet with<br>a new line.</p>')
29 end
29 end
30
31 def test_should_remove_style_tags_from_body
32 assert_equal "Text",
33 @parser.to_text('<html><body><style>body {font-size: 0.8em;}</style>Text</body></html>')
34 end
30 end
35 end
General Comments 0
You need to be logged in to leave comments. Login now