readability-rb 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: bcab6fa16fd851068954a9fa17a234e29f23f7406e094bc6f265954c29ce231a
4
+ data.tar.gz: c2866940fbd118a73065bd51de75491e9a02284ca0287953a53e8841d117029d
5
+ SHA512:
6
+ metadata.gz: 4ce2c23e7ddc3321dabd4bd45762c8c7950ceb4e3fb2bf1f48852c66937d0715f98027a0233b8e6f2a09628fc28f078eba8e68b2336c7f219890af3ddc9daae3
7
+ data.tar.gz: 86b0254a34654db1e910b3b8b0640fca6f77a1f518d29bd9816f49035e9308f492fb747be8e6b82257bdae7a2b184a7e13d469b91ed83e9fd1acdcacdbed3403
data/LICENSE ADDED
@@ -0,0 +1,189 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship made available under
36
+ the License, as indicated by a copyright notice that is included in
37
+ or attached to the work (an example is provided in the Appendix below).
38
+
39
+ "Derivative Works" shall mean any work, whether in Source or Object
40
+ form, that is based on (or derived from) the Work and for which the
41
+ editorial revisions, annotations, elaborations, or other modifications
42
+ represent, as a whole, an original work of authorship. For the purposes
43
+ of this License, Derivative Works shall not include works that remain
44
+ separable from, or merely link (or bind by name) to the interfaces of,
45
+ the Work and Derivative Works thereof.
46
+
47
+ "Contribution" shall mean, as submitted to the Licensor for inclusion
48
+ in the Work by the copyright owner or by an individual or Legal Entity
49
+ authorized to submit on behalf of the copyright owner. For the purposes
50
+ of this definition, "submitted" means any form of electronic, verbal,
51
+ or written communication sent to the Licensor or its representatives,
52
+ including but not limited to communication on electronic mailing lists,
53
+ source code control systems, and issue tracking systems that are managed
54
+ by, or on behalf of, the Licensor for the purpose of developing and
55
+ distributing the Work, but excluding communication that is conspicuously
56
+ marked or designated in writing by the copyright owner as "Not a
57
+ Contribution."
58
+
59
+ "Contributor" shall mean Licensor and any Legal Entity on behalf of
60
+ whom a Contribution has been received by the Licensor and included
61
+ within the Work.
62
+
63
+ 2. Grant of Copyright License. Subject to the terms and conditions of
64
+ this License, each Contributor hereby grants to You a perpetual,
65
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
66
+ copyright license to reproduce, prepare Derivative Works of,
67
+ publicly display, publicly perform, sublicense, and distribute the
68
+ Work and such Derivative Works in Source or Object form.
69
+
70
+ 3. Grant of Patent License. Subject to the terms and conditions of
71
+ this License, each Contributor hereby grants to You a perpetual,
72
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
73
+ (except as stated in this section) patent license to make, have made,
74
+ use, offer to sell, sell, import, and otherwise transfer the Work,
75
+ where such license applies only to those patent claims licensable
76
+ by such Contributor that are necessarily infringed by their
77
+ Contribution(s) alone or by the combination of their Contribution(s)
78
+ with the Work to which such Contribution(s) was submitted. If You
79
+ institute patent litigation against any entity (including a cross-claim
80
+ or counterclaim in a lawsuit) alleging that the Work or any
81
+ Contribution embodied within the Work constitutes patent or
82
+ contributory patent infringement, then any patent licenses granted to
83
+ You under this License for that Work shall terminate as of the date
84
+ such litigation is filed.
85
+
86
+ 4. Redistribution. You may reproduce and distribute copies of the
87
+ Work or Derivative Works thereof in any medium, with or without
88
+ modifications, and in Source or Object form, provided that You
89
+ meet the following conditions:
90
+
91
+ (a) You must give any other recipients of the Work or Derivative
92
+ Works a copy of this License; and
93
+
94
+ (b) You must cause any modified files to carry prominent notices
95
+ stating that You changed the files; and
96
+
97
+ (c) You must retain, in the Source form of any Derivative Works
98
+ that You distribute, all copyright, patent, trademark, and
99
+ attribution notices from the Source form of the Work,
100
+ excluding those notices that do not pertain to any part of
101
+ the Derivative Works; and
102
+
103
+ (d) If the Work includes a "NOTICE" text file as part of its
104
+ distribution, You must include a readable copy of the
105
+ attribution notices contained within such NOTICE file, in
106
+ at least one of the following places: within a NOTICE text
107
+ file distributed as part of the Derivative Works; within
108
+ the Source form or documentation, if provided along with the
109
+ Derivative Works; or, within a display generated by the
110
+ Derivative Works, if and wherever such third-party notices
111
+ normally appear. The contents of the NOTICE file are for
112
+ informational purposes only and do not modify the License.
113
+ You may add Your own attribution notices within Derivative
114
+ Works that You distribute, alongside or in addition to the
115
+ NOTICE text from the Work, provided that such additional
116
+ attribution notices cannot be construed as modifying the License.
117
+
118
+ You may add Your own license statement for Your modifications and
119
+ may provide additional grant of rights to use, copy, modify, merge,
120
+ publish, distribute, sublicense, and/or sell copies of the
121
+ Derivative Works as Your own modifications.
122
+
123
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
124
+ any Contribution intentionally submitted for inclusion in the Work
125
+ by You to the Licensor shall be under the terms and conditions of
126
+ this License, without any additional terms or conditions.
127
+ Notwithstanding the above, nothing herein shall supersede or modify
128
+ the terms of any separate license agreement you may have executed
129
+ with Licensor regarding such Contributions.
130
+
131
+ 6. Trademarks. This License does not grant permission to use the trade
132
+ names, trademarks, service marks, or product names of the Licensor,
133
+ except as required for reasonable and customary use in describing the
134
+ origin of the Work and reproducing the content of the NOTICE file.
135
+
136
+ 7. Disclaimer of Warranty. Unless required by applicable law or
137
+ agreed to in writing, Licensor provides the Work (and each
138
+ Contributor provides its Contributions) on an "AS IS" BASIS,
139
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
140
+ implied, including, without limitation, any warranties or conditions
141
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
142
+ PARTICULAR PURPOSE. You are solely responsible for determining the
143
+ appropriateness of using or reproducing the Work and assume any
144
+ risks associated with Your exercise of permissions under this License.
145
+
146
+ 8. Limitation of Liability. In no event and under no legal theory,
147
+ whether in tort (including negligence), contract, or otherwise,
148
+ unless required by applicable law (such as deliberate and grossly
149
+ negligent acts) or agreed to in writing, shall any Contributor be
150
+ liable to You for damages, including any direct, indirect, special,
151
+ incidental, or exemplary damages of any character arising as a
152
+ result of this License or out of the use or inability to use the
153
+ Work (including but not limited to damages for loss of goodwill,
154
+ work stoppage, computer failure or malfunction, or all and all
155
+ other commercial damages or losses), even if such Contributor
156
+ has been advised of the possibility of such damages.
157
+
158
+ 9. Accepting Warranty or Additional Liability. While redistributing
159
+ the Work or Derivative Works thereof, You may choose to offer,
160
+ and charge a fee for, acceptance of support, warranty, indemnity,
161
+ or other liability obligations and/or rights consistent with this
162
+ License. However, in accepting such obligations, You may offer only
163
+ conditions consistent with this License, and charge a fee for,
164
+ acceptance of warranty or liability obligations only on Your own behalf
165
+ and solely on Your terms, not on behalf of any other Contributor,
166
+ and only if You agree to indemnify, defend, and hold each Contributor
167
+ harmless for any liability incurred by, or claims asserted against,
168
+ such Contributor by reason of your accepting any such warranty or
169
+ additional liability.
170
+
171
+ END OF TERMS AND CONDITIONS
172
+
173
+ Copyright 2024 Arc90 Inc
174
+
175
+ This Ruby port (readability-rb) is based on Mozilla's Readability.js
176
+ (https://github.com/mozilla/readability), itself derived from Arc90's
177
+ original readability project.
178
+
179
+ Licensed under the Apache License, Version 2.0 (the "License");
180
+ you may not use this file except in compliance with the License.
181
+ You may obtain a copy of the License at
182
+
183
+ http://www.apache.org/licenses/LICENSE-2.0
184
+
185
+ Unless required by applicable law or agreed to in writing, software
186
+ distributed under the License is distributed on an "AS IS" BASIS,
187
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
188
+ See the License for the specific language governing permissions and
189
+ limitations under the License.
data/README.md ADDED
@@ -0,0 +1,107 @@
1
+ # Readability
2
+
3
+ Ruby port of [Mozilla Readability.js](https://github.com/mozilla/readability) -- extract readable article content from HTML pages, like Firefox Reader View.
4
+
5
+ [![Gem Version](https://img.shields.io/gem/v/readability-rb)](https://rubygems.org/gems/readability-rb)
6
+ [![Build Status](https://github.com/andycroll/readability-rb/actions/workflows/ci.yml/badge.svg)](https://github.com/andycroll/readability-rb/actions)
7
+ [![License](https://img.shields.io/badge/license-Apache%202.0-blue)](LICENSE)
8
+
9
+ Passes all 130 Mozilla test fixtures.
10
+
11
+ ## Installation
12
+
13
+ Add this line to your application's **Gemfile**:
14
+
15
+ ```ruby
16
+ gem "readability-rb"
17
+ ```
18
+
19
+ ## Quick Start
20
+
21
+ ```ruby
22
+ result = Readability.parse(html, url: "https://example.com/article")
23
+
24
+ result.title # article title
25
+ result.byline # author name
26
+ result.content # cleaned HTML content
27
+ result.text_content # plain text content
28
+ result.excerpt # short summary
29
+ result.length # text content length
30
+ result.site_name # site name
31
+ result.published_time # publication date
32
+ result.dir # text direction
33
+ result.lang # language
34
+ ```
35
+
36
+ ## Usage
37
+
38
+ ### Parse an article
39
+
40
+ ```ruby
41
+ html = Net::HTTP.get(URI("https://example.com/article"))
42
+ result = Readability.parse(html, url: "https://example.com/article")
43
+
44
+ puts result.title
45
+ puts result.content
46
+ ```
47
+
48
+ Returns a `Readability::Result` or `nil` if parsing fails.
49
+
50
+ ### Check if a page is readable
51
+
52
+ ```ruby
53
+ if Readability.readerable?(html)
54
+ result = Readability.parse(html)
55
+ end
56
+ ```
57
+
58
+ Accepts `min_score` and `min_content_length` options.
59
+
60
+ ```ruby
61
+ Readability.readerable?(html, min_score: 30, min_content_length: 200)
62
+ ```
63
+
64
+ ### Use the lower-level API
65
+
66
+ Pass a Nokogiri document directly.
67
+
68
+ ```ruby
69
+ doc = Nokogiri::HTML5(html)
70
+ result = Readability::Document.new(doc, url: "https://example.com").parse
71
+ ```
72
+
73
+ ### Custom serializer
74
+
75
+ Replace the default HTML serializer.
76
+
77
+ ```ruby
78
+ result = Readability.parse(html, serializer: ->(el) { el.to_html })
79
+ ```
80
+
81
+ ## Options
82
+
83
+ | Option | Description | Default |
84
+ | --- | --- | --- |
85
+ | `url` | Base URL for resolving relative links | `nil` |
86
+ | `max_elems_to_parse` | Max elements before aborting (0 = no limit) | `0` |
87
+ | `nb_top_candidates` | Number of top candidates to consider | `5` |
88
+ | `char_threshold` | Min characters for a successful parse | `500` |
89
+ | `classes_to_preserve` | CSS classes to keep on elements | `[]` |
90
+ | `keep_classes` | Preserve all CSS classes | `false` |
91
+ | `disable_json_ld` | Skip JSON-LD metadata extraction | `false` |
92
+ | `allowed_video_regex` | Regex for allowed video embed URLs | built-in |
93
+ | `link_density_modifier` | Adjust link density calculation | `0` |
94
+ | `serializer` | Lambda to serialize the content element | `inner_html` |
95
+
96
+ ## Contributing
97
+
98
+ Everyone is encouraged to help improve this project. Here are a few ways you can help:
99
+
100
+ - [Report bugs](https://github.com/andycroll/readability-rb/issues)
101
+ - Fix bugs and [submit pull requests](https://github.com/andycroll/readability-rb/pulls)
102
+ - Write, clarify, or fix documentation
103
+ - Suggest or add new features
104
+
105
+ ## License
106
+
107
+ Apache 2.0