ruby-readability 0.5.7 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +3 -0
- data/.travis.yml +6 -0
- data/.yardopts +3 -0
- data/Gemfile +1 -0
- data/LICENSE +202 -0
- data/README.md +103 -0
- data/lib/readability.rb +17 -5
- data/ruby-readability.gemspec +2 -2
- data/spec/fixtures/code.html +13 -0
- data/spec/readability_spec.rb +36 -1
- metadata +24 -33
- data/.document +0 -5
- data/CHANGES.markdown +0 -7
- data/README.markdown +0 -75
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 7c4e7dd91c7e7dbd34238150565daacd14d19c4f
|
4
|
+
data.tar.gz: fa8ef220bba559a5e3621de373bc3cb5295f9583
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 37f7e00448f2390cf87166899d967ad8521413b727e89a97f977310ceedf51e2f4a99201b046484bde645257ff9828ea3e1365056575776f107f50d0d1a8d15d
|
7
|
+
data.tar.gz: 2e4bcfceac1c8be2b2cd9cc9ed725f459f57bebfc87beaf940e972a2ed8b37e73d5681955b71a8cebc9ffee246e92b3f33cc8c983ec2ee97b201268149555e73
|
data/.gitignore
CHANGED
data/.travis.yml
ADDED
data/.yardopts
ADDED
data/Gemfile
CHANGED
data/LICENSE
ADDED
@@ -0,0 +1,202 @@
|
|
1
|
+
|
2
|
+
Apache License
|
3
|
+
Version 2.0, January 2004
|
4
|
+
http://www.apache.org/licenses/
|
5
|
+
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
7
|
+
|
8
|
+
1. Definitions.
|
9
|
+
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
12
|
+
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
14
|
+
the copyright owner that is granting the License.
|
15
|
+
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
17
|
+
other entities that control, are controlled by, or are under common
|
18
|
+
control with that entity. For the purposes of this definition,
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
20
|
+
direction or management of such entity, whether by contract or
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
23
|
+
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
25
|
+
exercising permissions granted by this License.
|
26
|
+
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
28
|
+
including but not limited to software source code, documentation
|
29
|
+
source, and configuration files.
|
30
|
+
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
32
|
+
transformation or translation of a Source form, including but
|
33
|
+
not limited to compiled object code, generated documentation,
|
34
|
+
and conversions to other media types.
|
35
|
+
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
37
|
+
Object form, made available under the License, as indicated by a
|
38
|
+
copyright notice that is included in or attached to the work
|
39
|
+
(an example is provided in the Appendix below).
|
40
|
+
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
47
|
+
the Work and Derivative Works thereof.
|
48
|
+
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
50
|
+
the original version of the Work and any modifications or additions
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
62
|
+
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
65
|
+
subsequently incorporated within the Work.
|
66
|
+
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
73
|
+
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
79
|
+
where such license applies only to those patent claims licensable
|
80
|
+
by such Contributor that are necessarily infringed by their
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
83
|
+
institute patent litigation against any entity (including a
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
86
|
+
or contributory patent infringement, then any patent licenses
|
87
|
+
granted to You under this License for that Work shall terminate
|
88
|
+
as of the date such litigation is filed.
|
89
|
+
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
92
|
+
modifications, and in Source or Object form, provided that You
|
93
|
+
meet the following conditions:
|
94
|
+
|
95
|
+
(a) You must give any other recipients of the Work or
|
96
|
+
Derivative Works a copy of this License; and
|
97
|
+
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
99
|
+
stating that You changed the files; and
|
100
|
+
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
103
|
+
attribution notices from the Source form of the Work,
|
104
|
+
excluding those notices that do not pertain to any part of
|
105
|
+
the Derivative Works; and
|
106
|
+
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
109
|
+
include a readable copy of the attribution notices contained
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
112
|
+
of the following places: within a NOTICE text file distributed
|
113
|
+
as part of the Derivative Works; within the Source form or
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
115
|
+
within a display generated by the Derivative Works, if and
|
116
|
+
wherever such third-party notices normally appear. The contents
|
117
|
+
of the NOTICE file are for informational purposes only and
|
118
|
+
do not modify the License. You may add Your own attribution
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
121
|
+
that such additional attribution notices cannot be construed
|
122
|
+
as modifying the License.
|
123
|
+
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
125
|
+
may provide additional or different license terms and conditions
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
129
|
+
the conditions stated in this License.
|
130
|
+
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
134
|
+
this License, without any additional terms or conditions.
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
136
|
+
the terms of any separate license agreement you may have executed
|
137
|
+
with Licensor regarding such Contributions.
|
138
|
+
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
141
|
+
except as required for reasonable and customary use in describing the
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
143
|
+
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
153
|
+
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
159
|
+
incidental, or consequential damages of any character arising as a
|
160
|
+
result of this License or out of the use or inability to use the
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
163
|
+
other commercial damages or losses), even if such Contributor
|
164
|
+
has been advised of the possibility of such damages.
|
165
|
+
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
169
|
+
or other liability obligations and/or rights consistent with this
|
170
|
+
License. However, in accepting such obligations, You may act only
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
175
|
+
of your accepting any such warranty or additional liability.
|
176
|
+
|
177
|
+
END OF TERMS AND CONDITIONS
|
178
|
+
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
180
|
+
|
181
|
+
To apply the Apache License to your work, attach the following
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
183
|
+
replaced with your own identifying information. (Don't include
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
185
|
+
comment syntax for the file format. We also recommend that a
|
186
|
+
file or class name and description of purpose be included on the
|
187
|
+
same "printed page" as the copyright notice for easier
|
188
|
+
identification within third-party archives.
|
189
|
+
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
191
|
+
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
193
|
+
you may not use this file except in compliance with the License.
|
194
|
+
You may obtain a copy of the License at
|
195
|
+
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
197
|
+
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
201
|
+
See the License for the specific language governing permissions and
|
202
|
+
limitations under the License.
|
data/README.md
ADDED
@@ -0,0 +1,103 @@
|
|
1
|
+
Ruby Readability
|
2
|
+
================
|
3
|
+
|
4
|
+
Ruby Readability is a tool for extracting the primary readable content of a
|
5
|
+
webpage. It is a Ruby port of arc90's readability project.
|
6
|
+
|
7
|
+
Build Status
|
8
|
+
------------
|
9
|
+
|
10
|
+
[![Build Status](https://travis-ci.org/cantino/ruby-readability.png)](https://travis-ci.org/cantino/ruby-readability)
|
11
|
+
|
12
|
+
Install
|
13
|
+
-------
|
14
|
+
|
15
|
+
Command line:
|
16
|
+
|
17
|
+
(sudo) gem install ruby-readability
|
18
|
+
|
19
|
+
Bundler:
|
20
|
+
|
21
|
+
gem "ruby-readability", :require => 'readability'
|
22
|
+
|
23
|
+
|
24
|
+
Example
|
25
|
+
-------
|
26
|
+
|
27
|
+
require 'rubygems'
|
28
|
+
require 'readability'
|
29
|
+
require 'open-uri'
|
30
|
+
|
31
|
+
source = open('http://lab.arc90.com/experiments/readability/').read
|
32
|
+
puts Readability::Document.new(source).content
|
33
|
+
|
34
|
+
|
35
|
+
Options
|
36
|
+
-------
|
37
|
+
|
38
|
+
You may provide options to `Readability::Document.new`, including:
|
39
|
+
|
40
|
+
* `:tags`: the base whitelist of tags to sanitize, defaults to `%w[div p]`;
|
41
|
+
* `:remove_empty_nodes`: remove `<p>` tags that have no text content; also
|
42
|
+
removes `<p>` tags that contain only images;
|
43
|
+
* `:attributes`: whitelist of allowed attributes;
|
44
|
+
* `:debug`: provide debugging output, defaults false;
|
45
|
+
* `:encoding`: if the page is of a known encoding, you can specify it; if left
|
46
|
+
unspecified, the encoding will be guessed (only in Ruby 1.9.x). If you wish
|
47
|
+
to disable guessing, supply `:do_not_guess_encoding => true`;
|
48
|
+
* `:html_headers`: in Ruby 1.9.x these will be passed to the
|
49
|
+
`guess_html_encoding` gem to aid with guessing the HTML encoding;
|
50
|
+
* `:ignore_image_format`: for use with .images. For example:
|
51
|
+
`:ignore_image_format => ["gif", "png"]`;
|
52
|
+
* `:min_image_height`: set a minimum image height for `#images`;
|
53
|
+
* `:min_image_width`: set a minimum image width for `#images`.
|
54
|
+
|
55
|
+
|
56
|
+
Command Line Tool
|
57
|
+
-----------------
|
58
|
+
|
59
|
+
Readability comes with a command-line tool for experimentation in
|
60
|
+
`bin/readability`.
|
61
|
+
|
62
|
+
Usage: readability [options] URL
|
63
|
+
-d, --debug Show debug output
|
64
|
+
-i, --images Keep images and links
|
65
|
+
-h, --help Show this message
|
66
|
+
|
67
|
+
|
68
|
+
Images
|
69
|
+
------
|
70
|
+
|
71
|
+
You can get a list of images in the content area with `Document#images`. This
|
72
|
+
feature requires that the `fastimage` gem be installed.
|
73
|
+
|
74
|
+
rbody = Readability::Document.new(body, :tags => %w[div p img a], :attributes => %w[src href], :remove_empty_nodes => false)
|
75
|
+
rbody.images
|
76
|
+
|
77
|
+
|
78
|
+
Potential Issues
|
79
|
+
----------------
|
80
|
+
|
81
|
+
If you're on a Mac and are getting segmentation faults, see the discussion at
|
82
|
+
<https://github.com/sparklemotion/nokogiri/issues/404> and consider updating
|
83
|
+
your version of `libxml2`. Version 2.7.8 of `libxml2`, installed with `brew`,
|
84
|
+
worked for me:
|
85
|
+
|
86
|
+
gem install nokogiri -- --with-xml2-include=/usr/local/Cellar/libxml2/2.7.8/include/libxml2 --with-xml2-lib=/usr/local/Cellar/libxml2/2.7.8/lib --with-xslt-dir=/usr/local/Cellar/libxslt/1.1.26
|
87
|
+
|
88
|
+
Or if you're using bundler and Rails 3, you can run this command to make
|
89
|
+
bundler always globally build `nokogiri` this way:
|
90
|
+
|
91
|
+
bundle config build.nokogiri -- --with-xml2-include=/usr/local/Cellar/libxml2/2.7.8/include/libxml2 --with-xml2-lib=/usr/local/Cellar/libxml2/2.7.8/lib --with-xslt-dir=/usr/local/Cellar/libxslt/1.1.26
|
92
|
+
|
93
|
+
|
94
|
+
License
|
95
|
+
-------
|
96
|
+
|
97
|
+
This code is under the Apache License 2.0. See <http://www.apache.org/licenses/LICENSE-2.0>.
|
98
|
+
|
99
|
+
Ruby port by cantino, starrhorne, libc, and iterationlabs. Special thanks to fizx and marcosinger.
|
100
|
+
|
101
|
+
|
102
|
+
[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/cantino/ruby-readability/trend.png)](https://bitdeli.com/free "Bitdeli Badge")
|
103
|
+
|
data/lib/readability.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
1
3
|
require 'rubygems'
|
2
4
|
require 'nokogiri'
|
3
5
|
require 'guess_html_encoding'
|
@@ -22,7 +24,7 @@ module Readability
|
|
22
24
|
@options = DEFAULT_OPTIONS.merge(options)
|
23
25
|
@input = input
|
24
26
|
|
25
|
-
if RUBY_VERSION =~ /^1\.9
|
27
|
+
if RUBY_VERSION =~ /^(1\.9|2)/ && !@options[:encoding]
|
26
28
|
@input = GuessHtmlEncoding.encode(@input, @options[:html_headers]) unless @options[:do_not_guess_encoding]
|
27
29
|
@options[:encoding] = @input.encoding.to_s
|
28
30
|
end
|
@@ -409,17 +411,27 @@ module Readability
|
|
409
411
|
|
410
412
|
# Otherwise, replace the element with its contents
|
411
413
|
else
|
412
|
-
|
413
|
-
|
414
|
+
# If element is root, replace the node as a text node
|
415
|
+
if el.parent.nil?
|
416
|
+
node = Nokogiri::XML::Text.new(el.text, el.document)
|
417
|
+
break
|
414
418
|
else
|
415
|
-
|
419
|
+
if replace_with_whitespace[el.node_name]
|
420
|
+
el.swap(Nokogiri::XML::Text.new(' ' << el.text << ' ', el.document))
|
421
|
+
else
|
422
|
+
el.swap(Nokogiri::XML::Text.new(el.text, el.document))
|
423
|
+
end
|
416
424
|
end
|
417
425
|
end
|
418
426
|
|
419
427
|
end
|
420
428
|
|
429
|
+
s = Nokogiri::XML::Node::SaveOptions
|
430
|
+
save_opts = s::NO_DECLARATION | s::NO_EMPTY_TAGS | s::AS_XHTML
|
431
|
+
html = node.serialize(:save_with => save_opts)
|
432
|
+
|
421
433
|
# Get rid of duplicate whitespace
|
422
|
-
|
434
|
+
return html.gsub(/[\r\n\f]+/, "\n" )
|
423
435
|
end
|
424
436
|
|
425
437
|
def clean_conditionally(node, candidates, selector)
|
data/ruby-readability.gemspec
CHANGED
@@ -3,10 +3,10 @@ $:.push File.expand_path("../lib", __FILE__)
|
|
3
3
|
|
4
4
|
Gem::Specification.new do |s|
|
5
5
|
s.name = "ruby-readability"
|
6
|
-
s.version = '0.
|
6
|
+
s.version = '0.6.0'
|
7
7
|
s.authors = ["Andrew Cantino", "starrhorne", "libc", "Kyle Maxwell"]
|
8
8
|
s.email = ["andrew@iterationlabs.com"]
|
9
|
-
s.homepage = "http://github.com/
|
9
|
+
s.homepage = "http://github.com/cantino/ruby-readability"
|
10
10
|
s.summary = %q{Port of arc90's readability project to ruby}
|
11
11
|
s.description = %q{Port of arc90's readability project to ruby}
|
12
12
|
|
data/spec/readability_spec.rb
CHANGED
@@ -472,5 +472,40 @@ describe Readability do
|
|
472
472
|
|
473
473
|
end
|
474
474
|
|
475
|
-
|
475
|
+
describe "Code blocks" do
|
476
|
+
before do
|
477
|
+
@code = File.read(File.dirname(__FILE__) + "/fixtures/code.html")
|
478
|
+
@content = Readability::Document.new(@code,
|
479
|
+
:tags => %w[div p img a ul ol li h1 h2 h3 h4 h5 h6 blockquote strong em b code pre],
|
480
|
+
:attributes => %w[src href],
|
481
|
+
:remove_empty_nodes => false).content
|
482
|
+
@doc = Nokogiri::HTML(@content)
|
483
|
+
end
|
484
|
+
|
485
|
+
it "preserve the code blocks" do
|
486
|
+
@doc.css("code pre").text.should == "\nroot\n indented\n "
|
487
|
+
end
|
488
|
+
|
489
|
+
it "preserve backwards code blocks" do
|
490
|
+
@doc.css("pre code").text.should == "\nsecond\n indented\n "
|
491
|
+
end
|
492
|
+
end
|
493
|
+
|
494
|
+
describe "remove all tags" do
|
495
|
+
it "should work for an incomplete piece of HTML" do
|
496
|
+
doc = Readability::Document.new('<div>test</div', :tags => [])
|
497
|
+
doc.content.should == 'test'
|
498
|
+
end
|
499
|
+
|
500
|
+
it "should work for a HTML document" do
|
501
|
+
doc = Readability::Document.new('<html><head><title>title!</title></head><body><div><p>test</p></div></body></html>',
|
502
|
+
:tags => [])
|
503
|
+
doc.content.should == 'test'
|
504
|
+
end
|
505
|
+
|
506
|
+
it "should work for a plain text" do
|
507
|
+
doc = Readability::Document.new('test', :tags => [])
|
508
|
+
doc.content.should == 'test'
|
509
|
+
end
|
510
|
+
end
|
476
511
|
end
|
metadata
CHANGED
@@ -1,8 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ruby-readability
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
5
|
-
prerelease:
|
4
|
+
version: 0.6.0
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Andrew Cantino
|
@@ -12,86 +11,76 @@ authors:
|
|
12
11
|
autorequire:
|
13
12
|
bindir: bin
|
14
13
|
cert_chain: []
|
15
|
-
date:
|
14
|
+
date: 2014-01-12 00:00:00.000000000 Z
|
16
15
|
dependencies:
|
17
16
|
- !ruby/object:Gem::Dependency
|
18
17
|
name: rspec
|
19
18
|
requirement: !ruby/object:Gem::Requirement
|
20
|
-
none: false
|
21
19
|
requirements:
|
22
|
-
- -
|
20
|
+
- - '>='
|
23
21
|
- !ruby/object:Gem::Version
|
24
22
|
version: '2.8'
|
25
23
|
type: :development
|
26
24
|
prerelease: false
|
27
25
|
version_requirements: !ruby/object:Gem::Requirement
|
28
|
-
none: false
|
29
26
|
requirements:
|
30
|
-
- -
|
27
|
+
- - '>='
|
31
28
|
- !ruby/object:Gem::Version
|
32
29
|
version: '2.8'
|
33
30
|
- !ruby/object:Gem::Dependency
|
34
31
|
name: rspec-expectations
|
35
32
|
requirement: !ruby/object:Gem::Requirement
|
36
|
-
none: false
|
37
33
|
requirements:
|
38
|
-
- -
|
34
|
+
- - '>='
|
39
35
|
- !ruby/object:Gem::Version
|
40
36
|
version: '2.8'
|
41
37
|
type: :development
|
42
38
|
prerelease: false
|
43
39
|
version_requirements: !ruby/object:Gem::Requirement
|
44
|
-
none: false
|
45
40
|
requirements:
|
46
|
-
- -
|
41
|
+
- - '>='
|
47
42
|
- !ruby/object:Gem::Version
|
48
43
|
version: '2.8'
|
49
44
|
- !ruby/object:Gem::Dependency
|
50
45
|
name: rr
|
51
46
|
requirement: !ruby/object:Gem::Requirement
|
52
|
-
none: false
|
53
47
|
requirements:
|
54
|
-
- -
|
48
|
+
- - '>='
|
55
49
|
- !ruby/object:Gem::Version
|
56
50
|
version: '1.0'
|
57
51
|
type: :development
|
58
52
|
prerelease: false
|
59
53
|
version_requirements: !ruby/object:Gem::Requirement
|
60
|
-
none: false
|
61
54
|
requirements:
|
62
|
-
- -
|
55
|
+
- - '>='
|
63
56
|
- !ruby/object:Gem::Version
|
64
57
|
version: '1.0'
|
65
58
|
- !ruby/object:Gem::Dependency
|
66
59
|
name: nokogiri
|
67
60
|
requirement: !ruby/object:Gem::Requirement
|
68
|
-
none: false
|
69
61
|
requirements:
|
70
|
-
- -
|
62
|
+
- - '>='
|
71
63
|
- !ruby/object:Gem::Version
|
72
64
|
version: 1.4.2
|
73
65
|
type: :runtime
|
74
66
|
prerelease: false
|
75
67
|
version_requirements: !ruby/object:Gem::Requirement
|
76
|
-
none: false
|
77
68
|
requirements:
|
78
|
-
- -
|
69
|
+
- - '>='
|
79
70
|
- !ruby/object:Gem::Version
|
80
71
|
version: 1.4.2
|
81
72
|
- !ruby/object:Gem::Dependency
|
82
73
|
name: guess_html_encoding
|
83
74
|
requirement: !ruby/object:Gem::Requirement
|
84
|
-
none: false
|
85
75
|
requirements:
|
86
|
-
- -
|
76
|
+
- - '>='
|
87
77
|
- !ruby/object:Gem::Version
|
88
78
|
version: 0.0.4
|
89
79
|
type: :runtime
|
90
80
|
prerelease: false
|
91
81
|
version_requirements: !ruby/object:Gem::Requirement
|
92
|
-
none: false
|
93
82
|
requirements:
|
94
|
-
- -
|
83
|
+
- - '>='
|
95
84
|
- !ruby/object:Gem::Version
|
96
85
|
version: 0.0.4
|
97
86
|
description: Port of arc90's readability project to ruby
|
@@ -102,12 +91,13 @@ executables:
|
|
102
91
|
extensions: []
|
103
92
|
extra_rdoc_files: []
|
104
93
|
files:
|
105
|
-
- .document
|
106
94
|
- .gitignore
|
107
95
|
- .rspec
|
108
|
-
-
|
96
|
+
- .travis.yml
|
97
|
+
- .yardopts
|
109
98
|
- Gemfile
|
110
|
-
-
|
99
|
+
- LICENSE
|
100
|
+
- README.md
|
111
101
|
- Rakefile
|
112
102
|
- bin/readability
|
113
103
|
- lib/readability.rb
|
@@ -115,6 +105,7 @@ files:
|
|
115
105
|
- ruby-readability.gemspec
|
116
106
|
- spec/fixtures/bbc.html
|
117
107
|
- spec/fixtures/cant_read.html
|
108
|
+
- spec/fixtures/code.html
|
118
109
|
- spec/fixtures/images/dim_1416768a.jpg
|
119
110
|
- spec/fixtures/images/sign_up_emails_682__703711a.gif
|
120
111
|
- spec/fixtures/images/sign_up_emails_682__703712a.gif
|
@@ -133,33 +124,33 @@ files:
|
|
133
124
|
- spec/readability_spec.rb
|
134
125
|
- spec/spec.opts
|
135
126
|
- spec/spec_helper.rb
|
136
|
-
homepage: http://github.com/
|
127
|
+
homepage: http://github.com/cantino/ruby-readability
|
137
128
|
licenses: []
|
129
|
+
metadata: {}
|
138
130
|
post_install_message:
|
139
131
|
rdoc_options: []
|
140
132
|
require_paths:
|
141
133
|
- lib
|
142
134
|
required_ruby_version: !ruby/object:Gem::Requirement
|
143
|
-
none: false
|
144
135
|
requirements:
|
145
|
-
- -
|
136
|
+
- - '>='
|
146
137
|
- !ruby/object:Gem::Version
|
147
138
|
version: '0'
|
148
139
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
149
|
-
none: false
|
150
140
|
requirements:
|
151
|
-
- -
|
141
|
+
- - '>='
|
152
142
|
- !ruby/object:Gem::Version
|
153
143
|
version: '0'
|
154
144
|
requirements: []
|
155
145
|
rubyforge_project: ruby-readability
|
156
|
-
rubygems_version:
|
146
|
+
rubygems_version: 2.0.3
|
157
147
|
signing_key:
|
158
|
-
specification_version:
|
148
|
+
specification_version: 4
|
159
149
|
summary: Port of arc90's readability project to ruby
|
160
150
|
test_files:
|
161
151
|
- spec/fixtures/bbc.html
|
162
152
|
- spec/fixtures/cant_read.html
|
153
|
+
- spec/fixtures/code.html
|
163
154
|
- spec/fixtures/images/dim_1416768a.jpg
|
164
155
|
- spec/fixtures/images/sign_up_emails_682__703711a.gif
|
165
156
|
- spec/fixtures/images/sign_up_emails_682__703712a.gif
|
data/.document
DELETED
data/CHANGES.markdown
DELETED
data/README.markdown
DELETED
@@ -1,75 +0,0 @@
|
|
1
|
-
# Ruby Readability
|
2
|
-
|
3
|
-
Ruby Readability is a tool for extracting the primary readable content of a webpage. It is a Ruby port of arc90's readability project.
|
4
|
-
|
5
|
-
## Install
|
6
|
-
|
7
|
-
Command line:
|
8
|
-
|
9
|
-
(sudo) gem install ruby-readability
|
10
|
-
|
11
|
-
Bundler:
|
12
|
-
|
13
|
-
gem "ruby-readability", :require => 'readability'
|
14
|
-
|
15
|
-
## Example
|
16
|
-
|
17
|
-
require 'rubygems'
|
18
|
-
require 'readability'
|
19
|
-
require 'open-uri'
|
20
|
-
|
21
|
-
source = open('http://lab.arc90.com/experiments/readability/').read
|
22
|
-
puts Readability::Document.new(source).content
|
23
|
-
|
24
|
-
## Options
|
25
|
-
|
26
|
-
You may provide options to Readability::Document.new, including:
|
27
|
-
|
28
|
-
:tags - the base whitelist of tags to sanitize, defaults to %w[div p]
|
29
|
-
:remove_empty_nodes - remove <p> tags that have no text content; also removes p tags that contain only images
|
30
|
-
:attributes - whitelist of allowed attributes
|
31
|
-
:debug - provide debugging output, defaults false
|
32
|
-
:encoding - if the page is of a known encoding, you can specify it; if left unspecified,
|
33
|
-
the encoding will be guessed (only in Ruby 1.9.x). If you wish to disable guessing,
|
34
|
-
supply :do_not_guess_encoding => true.
|
35
|
-
:html_headers - in Ruby 1.9.x these will be passed to the guess_html_encoding gem
|
36
|
-
to aid with guessing the HTML encoding
|
37
|
-
:ignore_image_format - for use with .images. For example: :ignore_image_format => ["gif", "png"]
|
38
|
-
:min_image_height - set a minimum image height for .images
|
39
|
-
:min_image_width - set a minimum image width for .images
|
40
|
-
|
41
|
-
## Command Line Tool
|
42
|
-
|
43
|
-
Readability comes with a command-line tool for experimentation in bin/readability.
|
44
|
-
|
45
|
-
Usage: readability [options] URL
|
46
|
-
-d, --debug Show debug output
|
47
|
-
-i, --images Keep images and links
|
48
|
-
-h, --help Show this message
|
49
|
-
|
50
|
-
## Images
|
51
|
-
|
52
|
-
You can get a list of images in the content area with `.images`. This feature requires that the `fastimage` gem be installed
|
53
|
-
|
54
|
-
rbody = Readability::Document.new(body, :tags => %w[div p img a], :attributes => %w[src href], :remove_empty_nodes => false)
|
55
|
-
rbody.images
|
56
|
-
|
57
|
-
## Potential Issues
|
58
|
-
|
59
|
-
If you're on a Mac and are getting segmentation faults, see the discussion at https://github.com/sparklemotion/nokogiri/issues/404 and consider updating your version of libxml2. Version 2.7.8 of libxml2, installed with `brew`, worked for me:
|
60
|
-
|
61
|
-
gem install nokogiri -- --with-xml2-include=/usr/local/Cellar/libxml2/2.7.8/include/libxml2 --with-xml2-lib=/usr/local/Cellar/libxml2/2.7.8/lib --with-xslt-dir=/usr/local/Cellar/libxslt/1.1.26
|
62
|
-
|
63
|
-
Or if you're using bundler and Rails 3, you can run this command to make bundler always globally build `nokogiri` this way
|
64
|
-
|
65
|
-
bundle config build.nokogiri -- --with-xml2-include=/usr/local/Cellar/libxml2/2.7.8/include/libxml2 --with-xml2-lib=/usr/local/Cellar/libxml2/2.7.8/lib --with-xslt-dir=/usr/local/Cellar/libxslt/1.1.26
|
66
|
-
|
67
|
-
# Change Log
|
68
|
-
|
69
|
-
* Version 0.5.1, released 3/13/2012 - The `ignore_image_format` option now defaults to an empty array, no longer excluding gif files by default. MiniMagic fetches are no longer attempted on local images.
|
70
|
-
|
71
|
-
# License
|
72
|
-
|
73
|
-
This code is under the Apache License 2.0. http://www.apache.org/licenses/LICENSE-2.0
|
74
|
-
|
75
|
-
Ruby port by starrhorne, libc, and iterationlabs. Special thanks to fizx and marcosinger.
|