Method: MarkdownToHtml::Renderer#initialize
- Defined in:
- lib/markdown_to_html.rb
#initialize(markdown_file = nil, html_file = nil) ⇒ Renderer
Returns a new instance of Renderer.
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/markdown_to_html.rb', line 18 def initialize(markdown_file = nil, html_file = nil) if markdown_file.nil? || %w(-h --help).include?(markdown_file) puts "Usage: markdown_to_html your_markdown_file [html]" return end markdown = Redcarpet::Markdown.new(HTMLWithPygments, :fenced_code_blocks => true, :no_intra_emphasis => true) article = markdown.render(File.new(markdown_file).read) html_file = "#{File.basename(markdown_file, File.extname(markdown_file))}.html" if html_file.nil? File.open(html_file, 'w') do |html| template = File.new(File.dirname(__FILE__) + '/markdown_to_html/template.html.erb').read html << ERB.new(template).result(binding) end end |