Last active
August 29, 2015 13:59
-
-
Save christianp/10852696 to your computer and use it in GitHub Desktop.
Fix multiple spaces in em tags containing three or fewer words
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
html.css('em,strong').each do |e| | |
if e.content.split.length <= 3 | |
e.search('//text()').each do |n| | |
if ends_with_space | |
n.content = n.text.gsub(/^\s/,"\u00A0") | |
end | |
n.content = n.text.gsub(/(?<=[\s\u00A0])\s/,"\u00A0") | |
ends_with_space = n.text.match(/\s$/) | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment