Skip to content

Instantly share code, notes, and snippets.

@baldwindavid
Created September 5, 2009 18:20
Show Gist options
  • Save baldwindavid/181471 to your computer and use it in GitHub Desktop.
Save baldwindavid/181471 to your computer and use it in GitHub Desktop.
# F MS Word
# This will cleanup 95% of the issues of copying from Word into a textarea.
# Notes:
# - This would be run on text already saved to the database
# - I am using Markdown convention for the bullets
# - I am being very lazy with em/en dashes - I could use Smarty Pants, but that opens up other issues
class WordCleanup
def self.clean(text)
unless text.nil?
# single quote
text = text.gsub('’', "'")
# em or en dash
text = text.gsub('–', "-")
# opening quote
text = text.gsub('“', '"')
# closing quote
text = text.gsub('”', '"')
# bullet point - convert to line break and Markdown bullet
text = text.gsub('•', "\r\n- ")
# colon
text = text.gsub("…", ":")
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment