Last active
July 8, 2016 16:56
-
-
Save jtprince/2db2fefdf926d5322c79a88bfd032ca7 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
#!/usr/bin/env ruby | |
# for working with Doba_Product descriptions | |
require 'redcarpet' | |
if ARGV.size == 0 | |
puts "usage: #{File.basename(__FILE__)} <file>.txt ..." | |
puts "output: text and html, ready for sql upload" | |
puts "" | |
puts "notes:" | |
puts '* will properly interpret \n chars in the text' | |
puts '* will produce \n chars in the html output ready for SQL insert' | |
puts "* converts the doba text email into one with html chars" | |
puts "* depends on redcarpet markdown converter (gem install redcarpet)" | |
end | |
# convert newlines into the newline character for sql upload | |
class String | |
def for_sql_insert | |
self.split("\n").join('\n') | |
end | |
end | |
options = { | |
autolink: true, # so the link will get hyperlinked | |
lax_spacing: true, # so we don't need a space between intro and the list | |
} | |
converter = Redcarpet::Markdown.new(Redcarpet::Render::HTML, **options) | |
ARGV.each do |file| | |
text = IO.read(file) | |
# we may be given text from the SQL insert statement that contains newline | |
# characters (not the newline itself). Convert these into actual newlines. | |
text.gsub!('\n', "\n") | |
puts "email_text_description:" | |
puts text.for_sql_insert | |
# make 1 space indented list flush with the beginning of the line | |
text.gsub!(/^ * /, '') | |
# embolden the "Doba <whatever> Package" at the start of the email | |
text.gsub!(/(Doba \w+ Package)\:/, '**\1**:') | |
html = converter.render(text) | |
puts "email_html_description:" | |
puts html.for_sql_insert | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment