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 +4 -4
- data/README.md +3 -1
- data/lib/ragadjust/adjust.rb +11 -1
- data/lib/ragadjust/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cb01392bb813c2aa3c81dedf44b39b809f07992e
|
4
|
+
data.tar.gz: 407c373a828f78b9a9c2a2c8e74d7a4f5be6b52b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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 )
|
data/lib/ragadjust/adjust.rb
CHANGED
@@ -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:]+)$/, ' \1')
|
68
|
+
end
|
69
|
+
|
70
|
+
end
|
71
|
+
|
62
72
|
html.css('body').inner_html
|
63
73
|
|
64
74
|
end # def self.ragadjust_content
|
data/lib/ragadjust/version.rb
CHANGED