texta 0.1.3 → 0.1.4
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +1 -1
- data/lib/texta.rb +24 -3
- data/texta.gemspec +1 -1
- metadata +1 -1
data/Rakefile
CHANGED
data/lib/texta.rb
CHANGED
@@ -13,7 +13,7 @@ module Texta
|
|
13
13
|
def self.is_html?(text)
|
14
14
|
return true if text =~ /&([a-z]+)|(#[0-9]+);/
|
15
15
|
|
16
|
-
text =~ /<(ul|p|br|li|b|i)\b(.*?)>/
|
16
|
+
text =~ /<(ul|a|p|br|li|b|i)\b(.*?)>/
|
17
17
|
end
|
18
18
|
|
19
19
|
module StringAdapter
|
@@ -66,6 +66,11 @@ module Texta
|
|
66
66
|
when "br"
|
67
67
|
"\n"
|
68
68
|
|
69
|
+
# links
|
70
|
+
when "a"
|
71
|
+
return "" unless node["href"]
|
72
|
+
"[" + children(node).join(" ") + "]" + "(" + node["href"] + ")"
|
73
|
+
|
69
74
|
# headlines
|
70
75
|
when /h([1-2])/
|
71
76
|
char = $1 == "1" ? "=" : "-"
|
@@ -75,6 +80,7 @@ module Texta
|
|
75
80
|
"#" * $1.to_i + " " + children(node).join(" ") + "\n\n"
|
76
81
|
|
77
82
|
# text nodes
|
83
|
+
|
78
84
|
when "text"
|
79
85
|
s = node.to_s.gsub(/(^\s+)|(\s+$)/, "")
|
80
86
|
s == "" ? nil : s
|
@@ -89,7 +95,9 @@ module Texta
|
|
89
95
|
"**" + children(node).join(" ") + "**"
|
90
96
|
when "td"
|
91
97
|
children(node).join(" ")
|
98
|
+
|
92
99
|
# lists
|
100
|
+
|
93
101
|
when "ul"
|
94
102
|
children(node).map { |s| "- #{s}\n" }.join + "\n"
|
95
103
|
when "li"
|
@@ -223,7 +231,7 @@ HTML
|
|
223
231
|
end
|
224
232
|
|
225
233
|
def test_table
|
226
|
-
input = <<-HTML
|
234
|
+
input = <<-HTML
|
227
235
|
<table><tr>
|
228
236
|
<th>Farben</th>
|
229
237
|
<td>halbtransparent, halbtransparent blau (Polycarbonat)</td>
|
@@ -263,5 +271,18 @@ HTML
|
|
263
271
|
|
264
272
|
assert_testa input, text, html
|
265
273
|
end
|
266
|
-
|
274
|
+
|
275
|
+
def test_link
|
276
|
+
input = "<a href='http://google.com'>Link</a>"
|
277
|
+
html = '<p><a href="http://google.com">Link</a></p>'
|
278
|
+
text = "[Link](http://google.com)"
|
279
|
+
assert_testa input, text, html
|
280
|
+
end
|
281
|
+
|
282
|
+
def test_anchor
|
283
|
+
input = "<a name='anchor'>test</a>ho!"
|
284
|
+
html = '<p>ho!</p>'
|
285
|
+
text = "\nho!"
|
286
|
+
assert_testa input, text, html
|
287
|
+
end
|
267
288
|
end
|
data/texta.gemspec
CHANGED