zevarito-undress 0.2 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
data/lib/undress.rb CHANGED
@@ -46,13 +46,9 @@ module Undress
46
46
  fixup_list(list) if list.parent != "li" && list.parent.name !~ /ul|ol/
47
47
  end
48
48
 
49
- (@doc/"span[@style*='italic']").each { |e| e.swap "<em>#{e.inner_html}</em>" }
50
-
51
- (@doc/"span[@style*='underline']").each { |e| e.swap "<ins>#{e.inner_html}</ins>" }
52
-
53
- (@doc/"span[@style*='line-through']").each { |e| e.swap "<del>#{e.inner_html}</del>" }
54
-
55
- (@doc/"span[@style*='bold']").each { |e| e.swap "<strong>#{e.inner_html}</strong>" }
49
+ (@doc/"p|span").each do |e|
50
+ fixup_span_with_styles(e)
51
+ end
56
52
  end
57
53
 
58
54
  # Delete tabs, newlines and more than 2 spaces from inside elements
@@ -67,6 +63,18 @@ module Undress
67
63
  end
68
64
  end
69
65
 
66
+ # For those elements like <span> if they are used to represent bold, italic
67
+ # such as those used on wysiwyg editors, we remove that after convert to not
68
+ # use them on the final convertion.
69
+ def fixup_span_with_styles(e)
70
+ return if !e.has_attribute?("style")
71
+
72
+ if e["style"] =~ /italic/ then e.inner_html = "<em>#{e.inner_html}</em>" end
73
+ if e["style"] =~ /underline/ then e.inner_html = "<ins>#{e.inner_html}</ins>" end
74
+ if e["style"] =~ /line-through/ then e.inner_html = "<del>#{e.inner_html}</del>" end
75
+ if e["style"] =~ /bold/ then e.inner_html = "<strong>#{e.inner_html}</strong>" end
76
+ end
77
+
70
78
  # Fixup a badly nested list such as <ul> sibling to <li> instead inside of <li>.
71
79
  def fixup_list(list)
72
80
  list.children.each {|e| fixup_list(e) if e.elem? && e.name =~ /ol|ul/}
@@ -21,10 +21,19 @@ class Undress::GreenClothTest < Test::Unit::TestCase
21
21
  # this is ok to ensure invalid html -> to greencloth but xhtmlize! must have
22
22
  # tests on test_undress or something too
23
23
  context "parsing not valid xhtml documents" do
24
- test "font-weight=bold styles in <span> elements should be <strong>" do
25
- html = "<p>some text <span style='font-weight=bold'>bold</span> with style</p>"
24
+ test "a <span> bold, italic, underline, line-through at the same time" do
25
+ html = "<p>some text <span style='font-weight:bold; font-style:italic; text-decoration:underline; text-decoration:line-through'>bold</span> with style</p>"
26
+ greencloth = "some text *-+_bold_+-* with style\n"
27
+ assert_renders_greencloth greencloth, html
28
+ end
29
+
30
+ test "font-weight:bold styles in <span> elements should be <strong>" do
31
+ html = "<p>some text <span style='font-weight:bold'>bold</span> with style</p>"
26
32
  greencloth = "some text *bold* with style\n"
27
33
  assert_renders_greencloth greencloth, html
34
+ html = "<p style='font-weight:bold'>some text bold with style</p>"
35
+ greencloth = "*some text bold with style*\n"
36
+ assert_renders_greencloth greencloth, html
28
37
  end
29
38
 
30
39
  test "style 'line-through' should be converted to <del> in <span> elements" do
@@ -32,7 +41,7 @@ class Undress::GreenClothTest < Test::Unit::TestCase
32
41
  greencloth = "with -some- in the -paragraph-\n"
33
42
  assert_renders_greencloth greencloth, html
34
43
  html = "<p style='text-decoration: line-through;'>with some in the paragraph</p>"
35
- greencloth = "with some in the paragraph\n"
44
+ greencloth = "-with some in the paragraph-\n"
36
45
  assert_renders_greencloth greencloth, html
37
46
  end
38
47
 
@@ -41,7 +50,7 @@ class Undress::GreenClothTest < Test::Unit::TestCase
41
50
  greencloth = "with +some+ in the +paragraph+\n"
42
51
  assert_renders_greencloth greencloth, html
43
52
  html = "<p style='text-decoration: underline;'>with some in the paragraph</p>"
44
- greencloth = "with some in the paragraph\n"
53
+ greencloth = "+with some in the paragraph+\n"
45
54
  assert_renders_greencloth greencloth, html
46
55
  end
47
56
 
@@ -50,7 +59,7 @@ class Undress::GreenClothTest < Test::Unit::TestCase
50
59
  greencloth = "with _some_ in the _paragraph_\n"
51
60
  assert_renders_greencloth greencloth, html
52
61
  html = "<p style='font-style: italic;'>with some in the paragraph</p>"
53
- greencloth = "with some in the paragraph\n"
62
+ greencloth = "_with some in the paragraph_\n"
54
63
  assert_renders_greencloth greencloth, html
55
64
  end
56
65
 
data/undress.gemspec CHANGED
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = "undress"
3
- s.version = "0.2"
3
+ s.version = "0.2.1"
4
4
  s.date = "2009-07-29"
5
5
 
6
6
  s.description = "Simply translate HTML to Textile, Markdown, or whatever other markup format you need"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: zevarito-undress
3
3
  version: !ruby/object:Gem::Version
4
- version: "0.2"
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - "Nicol\xC3\xA1s Sanguinetti"