20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
|
# File 'lib/touch_up.rb', line 20
def to_html
splits = Escape_Escape_Escape.html(@origin).gsub(HREFS) { |full, match|
raw_text = $2 ? Escape_Escape_Escape.decode_html($2) : nil
raw_append = Escape_Escape_Escape.decode_html $3
raw_link = (raw_append).first
if !raw_link
full
else
append = Escape_Escape_Escape.html raw_append.sub(raw_link, NOTHING)
text = if raw_text
Escape_Escape_Escape.html(raw_text)
else
Escape_Escape_Escape.html(raw_link)
end
raw_link = Escape_Escape_Escape.decode_html(raw_link)
if !raw_link['://']
raw_link = 'http://' + raw_link
end
begin
link = Escape_Escape_Escape.href(raw_link)
"<a href=\"#{link}\">#{text}</a>#{append}"
rescue Escape_Escape_Escape::Invalid_HREF
full
end
end
}.split(/(\<[^\>]+\>[^\<]+\<\/[^\>]+\>)/)
final = ""
i = 0
while i < splits.size
final << (splits[i].gsub(MARK_DOWNS) { |full, match|
case
when $1 == $3 && $1 == '/'
"<i>#{$2}</i>"
when $1 == '~~' && $3 == '~~'
"<del>#{$2}</del>"
when $1 == $3 && $1 == '*'
"<strong>#{$2}</strong>"
else
full
end
})
i += 1
if splits[i]
final << splits[i]
i += 1
end
end
final
end
|