require 'tempfile' require 'launchy' require 'rest_client' module Mdoc class Html < Text def convert htmlname = @file.gsub(/\.md$/, '.html') # content = `curl -X POST --data-urlencode content@#{@file} http://documentup.com/compiled` title = @title title = 'Preview' unless (title and title.size > 0) resp = RestClient.post 'http://documentup.com/compiled', :content => @body, :name => title content = resp.body # convert the received content content.gsub!('undefined', "#{title}") content.gsub!('', "") wfh = File.new(htmlname, 'w') wfh.write content wfh.close Launchy.open("file://" + htmlname) end end class Pandoc < Text def _convert type base_name = @file.gsub(/\.md$/, '') tmp_file = base_name + "__.md" tfh = File.new(tmp_file, 'w:utf-8') tfh.puts("% #{@title}") if @title tfh.puts("% #{@author}") if @author tfh.puts("% #{@date}") if @date tfh.puts("") tfh.puts(@body) tfh.close `pandoc -o #{base_name}.#{type} #{tmp_file}` File.unlink tmp_file end end class Rtf < Pandoc def convert; self._convert('rtf') end end class Docx < Pandoc def convert; self._convert('docx') end end class Pdf < Pandoc def convert self._convert('tex') basename = @file.gsub(/\.md$/, '') File.rename(basename + ".tex", basename + '__.tex') fh = File.new(@file.gsub(/\.md$/, '.tex'), 'w:utf-8') hd =<