ragadjust 0.0.5 → 0.0.6

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
  SHA1:
3
- metadata.gz: 566718eedb59f32cac4344e65f7d5b8a98522f48
4
- data.tar.gz: 77efa72194bb2e8f10e44efe76d6bf814a2dd713
3
+ metadata.gz: cb01392bb813c2aa3c81dedf44b39b809f07992e
4
+ data.tar.gz: 407c373a828f78b9a9c2a2c8e74d7a4f5be6b52b
5
5
  SHA512:
6
- metadata.gz: 203f3105f1d3294b997f22be43aa341c590e9d00ed55c2891c2e112a31157221d7dd0e783749b3a872517ff8f6288c6cd53705a0d901882d687e4790618620f1
7
- data.tar.gz: a5ca59d3bbf9f74a0160afcb0dd635d48aa7789b494502a9081f6804f7f3fdad668699147d9d3b20630eb1d4078f161ccd3eb26b79a6e1715fea9ea04371916b
6
+ metadata.gz: 0b301c1c301294e642364b27b734a1f957b22d6d7379ad3ff1d63734cfc23489bc718a79c289777ed9245b7fc0e2ae9450505f1ce295dce0cb247cc96f81350b
7
+ data.tar.gz: c29e515305927bf22cd3883ae58b7a79792791692b84ed6956a57d32d3c18561efffd9b170a18af1e4bdc7c6235b2e5426dba0c6604ba73257bf46ed08cd9cae
data/README.md CHANGED
@@ -18,7 +18,7 @@ Or install it yourself as:
18
18
 
19
19
  ## Usage
20
20
 
21
- Ragadjust::Adjust.ragadjust_content(text_to_adjust, selector, method)
21
+ Ragadjust::Adjust.ragadjust_content(text_to_adjust, selector, method, orphans)
22
22
 
23
23
  `selector` takes a CSS selector and defaults to:
24
24
 
@@ -32,6 +32,8 @@ Or install it yourself as:
32
32
  'dashes' - only adjust space after dashes
33
33
  'emphasis' - only adjust within emphasis tags (em, strong, i, b)
34
34
 
35
+ `orphans` defaults to true and will add a non-breaking space before the last word in an h1-h6 tag
36
+
35
37
  ## Contributing
36
38
 
37
39
  1. Fork it ( https://github.com/aperfect/ragadjust/fork )
@@ -6,7 +6,7 @@ module Ragadjust
6
6
 
7
7
  # Rag-adjust the content. Based on Nathan Ford's ragadjust JS
8
8
  # https://github.com/nathanford/ragadjust
9
- def self.ragadjust_content(text_to_adjust, selector = 'p, li, dd, figcaption', method = 'all')
9
+ def self.ragadjust_content(text_to_adjust, selector = 'p, li, dd, figcaption', method = 'all', orphans = true)
10
10
  html = Nokogiri::HTML(text_to_adjust) # Not using .fragment() as .search() doesn't seem to work?
11
11
 
12
12
  preps = /(?<=\s|^|;)((aboard|about|above|across|after|against|along|amid|among|anti|around|before|behind|below|beneath|beside|besides|between|beyond|concerning|considering|despite|down|during|except|excepting|excluding|following|from|inside|into|like|minus|near|onto|opposite|outside|over|past|plus|regarding|round|save|since|than|that|this|through|toward|towards|under|underneath|unlike|until|upon|versus|with|within|without)\s)+/i
@@ -59,6 +59,16 @@ module Ragadjust
59
59
  end # elements.css().each
60
60
  end
61
61
 
62
+ # avoid orphaned words at end of headings
63
+ if orphans
64
+ elements.css('h1,h2,h3,h4,h5.h6').each do |el|
65
+ last_text = el.search('.//text()').last
66
+
67
+ last_text.content = last_text.content.gsub(/\s+([:word:]+)$/, '&nbsp;\1')
68
+ end
69
+
70
+ end
71
+
62
72
  html.css('body').inner_html
63
73
 
64
74
  end # def self.ragadjust_content
@@ -1,3 +1,3 @@
1
1
  module Ragadjust
2
- VERSION = "0.0.5"
2
+ VERSION = "0.0.6"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ragadjust
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Adam Perfect