Created
September 5, 2009 18:20
-
-
Save baldwindavid/181471 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
# 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