readability-rb 0.9.0 → 0.9.1
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 +4 -4
- data/lib/readability/version.rb +1 -1
- data/lib/readability.rb +13 -2
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 4571b7715f1e0980abd507f1420e793de091611a46ea3e10db606b19f2bc2f7b
|
|
4
|
+
data.tar.gz: e7e2426c6394d76e225d978db5877b56ab28c536c6ff6a0bcbd694bde66b61d3
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 9fdbe2a9504d10a74ef1f25028b2d89640ad43b52e42449a11af1619cea5f58ba064f47c636c6f49eaf989eee099442fcbc7a85e3fb783106f70a7ea4822f2a5
|
|
7
|
+
data.tar.gz: 3df7a29716c46345a7611534b18e6253014995ce808cb5ff429a185c50ae379b84d54b7e52600f769e02b194db3be54ff8872eccc244b5fff776a1c7dc460135
|
data/lib/readability/version.rb
CHANGED
data/lib/readability.rb
CHANGED
|
@@ -19,12 +19,23 @@ module Readability
|
|
|
19
19
|
DEFAULT_MAX_TREE_DEPTH = 1000
|
|
20
20
|
|
|
21
21
|
def self.parse(html, url: nil, max_attributes: DEFAULT_MAX_ATTRIBUTES, max_tree_depth: DEFAULT_MAX_TREE_DEPTH, **options)
|
|
22
|
-
doc =
|
|
22
|
+
doc = parse_html(html, max_attributes: max_attributes, max_tree_depth: max_tree_depth)
|
|
23
23
|
Document.new(doc, url: url, **options).parse
|
|
24
24
|
end
|
|
25
25
|
|
|
26
26
|
def self.readerable?(html, max_attributes: DEFAULT_MAX_ATTRIBUTES, max_tree_depth: DEFAULT_MAX_TREE_DEPTH, **options)
|
|
27
|
-
doc =
|
|
27
|
+
doc = parse_html(html, max_attributes: max_attributes, max_tree_depth: max_tree_depth)
|
|
28
28
|
Readerable.probably_readerable?(doc, **options)
|
|
29
29
|
end
|
|
30
|
+
|
|
31
|
+
# Nokogiri's HTML5 parser converts the page to UTF-8 strictly, so a byte the page's
|
|
32
|
+
# charset doesn't define raises. Browsers replace such bytes with U+FFFD, so convert
|
|
33
|
+
# the page that way, in the charset Nokogiri chose, and parse it again.
|
|
34
|
+
def self.parse_html(html, **limits)
|
|
35
|
+
Nokogiri::HTML5(html, **limits)
|
|
36
|
+
rescue Encoding::UndefinedConversionError, Encoding::InvalidByteSequenceError => e
|
|
37
|
+
utf8 = html.dup.force_encoding(e.source_encoding).encode(Encoding::UTF_8, invalid: :replace, undef: :replace)
|
|
38
|
+
Nokogiri::HTML5(utf8, **limits)
|
|
39
|
+
end
|
|
40
|
+
private_class_method :parse_html
|
|
30
41
|
end
|