mirror of
https://github.com/discourse/discourse.git
synced 2025-01-30 05:05:15 +08:00
Rewrite capitalize for readability
Makes capitalize logic more clear with @sam suggestion
This commit is contained in:
parent
decb744c76
commit
adae5d78f5
|
@ -33,7 +33,10 @@ class TextCleaner
|
||||||
# Replace all-caps text with regular case letters
|
# Replace all-caps text with regular case letters
|
||||||
text = text.mb_chars.downcase.to_s if opts[:replace_all_upper_case] && (text =~ /[A-Z]+/) && (text == text.upcase)
|
text = text.mb_chars.downcase.to_s if opts[:replace_all_upper_case] && (text =~ /[A-Z]+/) && (text == text.upcase)
|
||||||
# Capitalize first letter, but only when entire first word is lowercase
|
# Capitalize first letter, but only when entire first word is lowercase
|
||||||
text = text.mb_chars.capitalize.to_s if opts[:capitalize_first_letter] && (text =~ /\S+/) && text.split(' ').first == text.split(' ').first.mb_chars.downcase
|
first, rest = text.split(' ', 2)
|
||||||
|
if opts[:capitalize_first_letter] && first == first.mb_chars.downcase
|
||||||
|
text = "#{first.mb_chars.capitalize}#{rest ? ' ' + rest : ''}"
|
||||||
|
end
|
||||||
# Remove unnecessary periods at the end
|
# Remove unnecessary periods at the end
|
||||||
text.sub!(/([^.])\.+(\s*)\z/, '\1\2') if opts[:remove_all_periods_from_the_end]
|
text.sub!(/([^.])\.+(\s*)\z/, '\1\2') if opts[:remove_all_periods_from_the_end]
|
||||||
# Remove extraneous space before the end punctuation
|
# Remove extraneous space before the end punctuation
|
||||||
|
|
Loading…
Reference in New Issue
Block a user