Created
September 7, 2013 17:23
-
-
Save PeteMichaud/6477449 to your computer and use it in GitHub Desktop.
Revisions
-
PeteMichaud created this gist
Sep 7, 2013 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,26 @@ require 'html2markdown' #gem install html2markdown dirs = %w(_pages _posts) class String def word_wrap(line_width = 120) self.split("\n").collect do |line| line.length > line_width ? line.gsub(/(.{1,#{line_width}})(\s+|$)/, "\\1\n").strip : line end * "\n" end end def md(file_name) file_name.chomp(File.extname(file_name)) + '.md' end dirs.each do |dir| Dir.open(dir) do |d_handle| d_handle.reject{ |f| f == '.' || f == '..' }.each do |file_name| content = HTMLPage.new(:contents => File.read("#{dir}/#{file_name}")) File.write("#{dir}/#{md(file_name)}", content.markdown.word_wrap) end end end