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 +15 -7
- data/test/test_greencloth.rb +14 -5
- data/undress.gemspec +1 -1
- metadata +1 -1
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
|
50
|
-
|
51
|
-
|
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/}
|
data/test/test_greencloth.rb
CHANGED
@@ -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 "
|
25
|
-
html = "<p>some text <span style='font-weight
|
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
|
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
|
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 = "
|
62
|
+
greencloth = "_with some in the paragraph_\n"
|
54
63
|
assert_renders_greencloth greencloth, html
|
55
64
|
end
|
56
65
|
|
data/undress.gemspec
CHANGED