Skip to content

Instantly share code, notes, and snippets.

@christianp
Last active August 29, 2015 13:59
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save christianp/10852696 to your computer and use it in GitHub Desktop.
Save christianp/10852696 to your computer and use it in GitHub Desktop.
Fix multiple spaces in em tags containing three or fewer words
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