html_to_plain_text 1.0.0 → 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.0.0
1
+ 1.0.1
@@ -18,6 +18,7 @@ module HtmlToPlainText
18
18
  LI = "li".freeze
19
19
  NUMBERS = ["1", "a"]
20
20
  ABSOLUTE_URL_PATTERN = /^[a-z]+:\/\/[a-z0-9]/i
21
+ HTML_PATTERN = /[<&]/
21
22
 
22
23
  # Helper instance method for converting HTML into plain text. This method simply calls HtmlToPlainText.plain_text.
23
24
  def plain_text(html)
@@ -27,7 +28,8 @@ module HtmlToPlainText
27
28
  class << self
28
29
  # Convert some HTML into a plain text approximation.
29
30
  def plain_text(html)
30
- return if html.nil? || html.empty?
31
+ return nil if html.nil?
32
+ return html.dup unless html.match(HTML_PATTERN)
31
33
  body = Nokogiri::HTML::Document.parse(html).css("body").first
32
34
  return unless body
33
35
  convert_node_to_plain_text(body).strip.gsub(/\r(\n?)/, "\n")
@@ -90,4 +90,16 @@ describe HtmlToPlainText do
90
90
  html = "This &amp; th&#97;t"
91
91
  HtmlToPlainText.plain_text(html).should == "This & that"
92
92
  end
93
+
94
+ it "should handle nil" do
95
+ HtmlToPlainText.plain_text(nil).should == nil
96
+ end
97
+
98
+ it "should handle empty text" do
99
+ HtmlToPlainText.plain_text("").should == ""
100
+ end
101
+
102
+ it "should handle non-html text" do
103
+ HtmlToPlainText.plain_text("test").should == "test"
104
+ end
93
105
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: html_to_plain_text
3
3
  version: !ruby/object:Gem::Version
4
- hash: 23
4
+ hash: 21
5
5
  prerelease:
6
6
  segments:
7
7
  - 1
8
8
  - 0
9
- - 0
10
- version: 1.0.0
9
+ - 1
10
+ version: 1.0.1
11
11
  platform: ruby
12
12
  authors:
13
13
  - Brian Durand
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-06-08 00:00:00 -05:00
18
+ date: 2011-06-21 00:00:00 -05:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency