@@ -23,7 +23,8 module Redmine | |||
|
23 | 23 | |
|
24 | 24 | class_attribute :tags |
|
25 | 25 | self.tags = { |
|
26 | 'br' => {:post => "\n"} | |
|
26 | 'br' => {:post => "\n"}, | |
|
27 | 'style' => '' | |
|
27 | 28 | } |
|
28 | 29 | |
|
29 | 30 | def self.to_text(html) |
@@ -44,9 +45,16 module Redmine | |||
|
44 | 45 | |
|
45 | 46 | def scrub(node) |
|
46 | 47 | formatting = @tags_to_text[node.name] |
|
47 |
|
|
|
48 | case formatting | |
|
49 | when Hash | |
|
48 | 50 | node.add_next_sibling Nokogiri::XML::Text.new("#{formatting[:pre]}#{node.content}#{formatting[:post]}", node.document) |
|
49 | 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 | 58 | end |
|
51 | 59 | end |
|
52 | 60 | end |
@@ -32,7 +32,8 module Redmine | |||
|
32 | 32 | 'h3' => {:pre => "\n\n### ", :post => "\n\n"}, |
|
33 | 33 | 'h4' => {:pre => "\n\n#### ", :post => "\n\n"}, |
|
34 | 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 | 38 | end |
|
38 | 39 | end |
@@ -33,7 +33,8 module Redmine | |||
|
33 | 33 | 'h3' => {:pre => "\n\nh3. ", :post => "\n\n"}, |
|
34 | 34 | 'h4' => {:pre => "\n\nh4. ", :post => "\n\n"}, |
|
35 | 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 | 39 | end |
|
39 | 40 | end |
@@ -27,4 +27,9 class Redmine::WikiFormatting::HtmlParserTest < ActiveSupport::TestCase | |||
|
27 | 27 | assert_equal "A html snippet with\na new line.", |
|
28 | 28 | @parser.to_text('<p>A html snippet with<br>a new line.</p>') |
|
29 | 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 | 35 | end |
General Comments 0
You need to be logged in to leave comments.
Login now