Sha256: 5a44d57b1f122d13eff6f8117fc2786416b5c3283c907965374cba0b8673d405

Contents?: true

Size: 1.43 KB

Versions: 2

Compression:

Stored size: 1.43 KB

Contents

#!/usr/bin/env ruby
require 'redcarpet'
require 'hubdown/cli_parser'
require 'hubdown/page_builder'
require 'hubdown/pygments_renderer'

def init
  @file_name = ARGV.shift
  output = ""
  parser = CliParser.new
  parser.run ARGV
  mdown = create_mdown

  if parser.config[:output] || parser.config[:wrap]
    page_data = create_page mdown
    if parser.config[:output]
      File.open( parser.config[:output], "w" ) { |f| f.write page_data } 
    end
    if parser.config[:wrap]
      output = page_data
    end
  else
    output = mdown
  end

  if output != ""
    puts output
  end

end

def create_page mdown
  options = { 
    "body" => mdown, 
    "filename" => @file_name, 
    "uri" => 'https://github.com/knomedia/hubdown'
  } 
  p = Hubdown::PageBuilder.new options
  page_data = p.get_page
  page_data
end


def create_mdown
  md_options = { :autolink => true,
                 :no_intra_emphasis => true,
                 :space_after_headers => true,
                 :fenced_code_blocks => true,
                 :tables => true,
                 :strikethrough => true,
                 :lax_spacing => true,
                 :space_after_headers => true,
                 :superscript => true
               }
  renderer = PygmentsRenderer.new({ :hard_wrap => true })
  markdown = Redcarpet::Markdown.new(renderer, md_options) 
  contents = ""
  File.open( @file_name, 'r') {|f| contents = f.read() }
  md = markdown.render( contents )
  md
end

init

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
hubdown-0.0.11 bin/hubdown
hubdown-0.0.10 bin/hubdown