readability-rb 0.7.0 → 0.8.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9face7faf604c0ce94f2ad0db7bd6537bb0b46ec34703e8d8711f67e11249071
4
- data.tar.gz: 8ce547233f221524924bf3678eecee1b9da566d16ac025586050a480693f6861
3
+ metadata.gz: 1a1b61ac01f8639dc5ebd9219be2c129f739913aa31b80755985cce993586947
4
+ data.tar.gz: '0093eca156a35705d9bed99d33e31f0cfbdb23f4421c844a29b22b8ee17c7a52'
5
5
  SHA512:
6
- metadata.gz: f90592e96640dee76abced9686165b9bb3d20254df78c157c70108929234c3bfd5bc2049472263c5e7ce32fac07627402beb64a1f1bca46510a15c0b146f07c5
7
- data.tar.gz: 6b79072fb4874ec9881cce4c3b44dd90880fb3fb31a7b9c20b0130db658ac7a806f2c29d1113e4484d25ef7776eede73809edf37f3467d18e58361b0d95c67b4
6
+ metadata.gz: 952f8342972eba74060d8302febc3ff5a6f6f1f87de0d5b98ec50a2a0ed9476592a1d32ea195f61c0dd03473611799586e6a59150b2145979d9c76db5b1c92b9
7
+ data.tar.gz: 5e277f3a164204f8def9ba19d7e0fc3f85dfc39bf9aaaa25b8fd8110336fa9bb20c74ad796ddb07b35ef48d272a63f48212d1ea0a9767bf9cc1c012a3e54cd42
@@ -128,7 +128,7 @@ module Readability
128
128
  orig_title = ""
129
129
 
130
130
  begin
131
- cur_title = orig_title = (@doc.at_css("title")&.text&.strip || "")
131
+ cur_title = orig_title = js_trim(@doc.at_css("title")&.text || "")
132
132
 
133
133
  # If title came back as something other than a string (shouldn't happen
134
134
  # with Nokogiri, but match JS logic)
@@ -140,16 +140,17 @@ module Readability
140
140
  end
141
141
 
142
142
  title_had_hierarchical_separators = false
143
- word_count = ->(str) { str.split(/\s+/).length }
143
+ space = '[[:space:]\uFEFF]'
144
+ word_count = ->(str) { str.split(/#{space}+/, -1).length }
144
145
 
145
146
  # Title separator characters — exact JS source string from line 597
146
147
  title_separators = '\|\-\u2013\u2014\\\\\/>»'
147
148
 
148
- if cur_title.match?(/\s[#{title_separators}]\s/)
149
- title_had_hierarchical_separators = cur_title.match?(/\s[\\\/>\u00BB]\s/)
149
+ if cur_title.match?(/#{space}[#{title_separators}]#{space}/)
150
+ title_had_hierarchical_separators = cur_title.match?(/#{space}[\\\/>\u00BB]#{space}/)
150
151
 
151
152
  # Find all separator positions and remove everything after the last one
152
- all_separators = orig_title.to_enum(:scan, /\s[#{title_separators}]\s/i).map { Regexp.last_match }
153
+ all_separators = orig_title.to_enum(:scan, /#{space}[#{title_separators}]#{space}/i).map { Regexp.last_match }
153
154
  cur_title = orig_title[0, all_separators.last.begin(0)]
154
155
 
155
156
  # If the resulting title is too short, remove the first part instead
@@ -159,8 +160,8 @@ module Readability
159
160
  elsif cur_title.include?(": ")
160
161
  # Check if we have a heading containing this exact string
161
162
  headings = get_all_nodes_with_tag(@doc, ["h1", "h2"])
162
- trimmed_title = cur_title.strip
163
- match = headings.any? { |heading| heading.text.strip == trimmed_title }
163
+ trimmed_title = js_trim(cur_title)
164
+ match = headings.any? { |heading| js_trim(heading.text) == trimmed_title }
164
165
 
165
166
  # If we don't, extract the title out of the original title string
166
167
  unless match
@@ -182,7 +183,7 @@ module Readability
182
183
  end
183
184
  end
184
185
 
185
- cur_title = cur_title.strip.gsub(NORMALIZE, " ")
186
+ cur_title = js_trim(cur_title).gsub(NORMALIZE, " ")
186
187
 
187
188
  # If we now have 4 words or fewer as our title, and either no
188
189
  # 'hierarchical' separators (\, /, > or ») were found in the original
@@ -192,7 +193,7 @@ module Readability
192
193
  if cur_title_word_count <= 4 &&
193
194
  (!title_had_hierarchical_separators ||
194
195
  cur_title_word_count !=
195
- word_count.call(orig_title.gsub(/\s[#{title_separators}]\s/, "")) - 1)
196
+ word_count.call(orig_title.gsub(/#{space}[#{title_separators}]#{space}/, "")) - 1)
196
197
  cur_title = orig_title
197
198
  end
198
199
 
@@ -33,7 +33,8 @@ module Readability
33
33
 
34
34
  REPLACE_FONTS = /<(\/?)font[^>]*>/i
35
35
 
36
- NORMALIZE = /\s{2,}/
36
+ # JS \s matches Unicode spaces such as NBSP; Ruby's \s is ASCII-only.
37
+ NORMALIZE = /[[:space:]\uFEFF]{2,}/
37
38
 
38
39
  VIDEOS = /\/\/(www\.)?((dailymotion|youtube|youtube-nocookie|player\.vimeo|v\.qq|bilibili|live.bilibili)\.com|(archive|upload\.wikimedia)\.org|player\.twitch\.tv)/i
39
40
 
@@ -45,9 +46,9 @@ module Readability
45
46
 
46
47
  TOKENIZE = /\W+/
47
48
 
48
- WHITESPACE = /\A\s*\z/
49
+ WHITESPACE = /\A[[:space:]\uFEFF]*\z/
49
50
 
50
- HAS_CONTENT = /\S\z/
51
+ HAS_CONTENT = /[^[:space:]\uFEFF]\z/
51
52
 
52
53
  HASH_URL = /\A#.+/
53
54
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Readability
4
- VERSION = "0.7.0"
4
+ VERSION = "0.8.0"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: readability-rb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.0
4
+ version: 0.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andy Croll