texta 0.1.3 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. data/Rakefile +1 -1
  2. data/lib/texta.rb +24 -3
  3. data/texta.gemspec +1 -1
  4. metadata +1 -1
data/Rakefile CHANGED
@@ -2,7 +2,7 @@ require 'rubygems'
2
2
  require 'rake'
3
3
  require 'echoe'
4
4
 
5
- Echoe.new('texta', '0.1.3') do |p|
5
+ Echoe.new('texta', '0.1.4') do |p|
6
6
  p.description = "texta: heuristic text formatting"
7
7
  p.url = "http://github.com/pboy/texta"
8
8
  p.author = "pboy"
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
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{texta}
5
- s.version = "0.1.3"
5
+ s.version = "0.1.4"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["pboy"]
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: texta
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - pboy