-
Notifications
You must be signed in to change notification settings - Fork 1
/
ragadjust.rb
43 lines (37 loc) · 1.49 KB
/
ragadjust.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
module Jekyll
module Filters
def ragadjust(text, method = 'all')
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
smallwords = /(\s|^)(([a-zA-Z-_(]{1,2}('|’)*[a-zA-Z-_,;]{0,1}?\s)+)/i # words with 3 or less characters
dashes = /\s([-–—])/i
emphasis = /(<(strong|em|b|i)>)(([^\s]+\s*){2,3})?(<\/(strong|em|b|i)>)/i
numbers = /([0-9])+\s/
if method === 'small-words' || method === 'all'
text.gsub!(smallwords) {
Regexp.last_match[1] + Regexp.last_match[2].gsub(/\s/i, ' ')
}
end
if method === 'prepositions' || method === 'all'
text.gsub!(preps) {
Regexp.last_match[1] + Regexp.last_match[2].gsub(/\s/i, ' ')
}
end
if method === 'dashes' || method === 'all'
text.gsub!(dashes) { |match|
match.gsub(/\s/, ' ')
}
end
if method === 'emphasis' || method === 'all'
text.gsub!(dashes) {
Regexp.last_match[1] + Regexp.last_match[3].gsub(/\s/i, ' ') + Regexp.last_match[5]
}
end
if method === 'numbers' || method === 'all'
text.gsub!(numbers) { |match|
match.gsub(/\s/, ' ')
}
end
text
end
end
end