Class: M2H::Render

Inherits:
Object
  • Object
show all
Defined in:
lib/m2h/render.rb

Defined Under Namespace

Classes: Document

Class Method Summary collapse

Class Method Details

.render!(base) ⇒ Object



57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/m2h/render.rb', line 57

def self.render!(base)
  markdown = Redcarpet::Markdown.new(
    Redcarpet::Render::HTML,
    space_after_headers: true,
    fenced_code_blocks: true,
    no_intra_emphasis: true,
    strikethrough: true,
    footnotes: true,
    autolink: true,
    tables: true,
    with_toc_data: true,
  )

  base.files.each { |bf|
    doc = Document.new(markdown.render(File.open(bf, "r:utf-8").read))
    doc.set_serif if base.serif
    doc.set_header if base.header
    doc.set_cover if base.cover
    doc.set_toc if base.toc
    doc.write("#{bf}.html".encode(base.sys_enc), "w:#{base.sys_enc}")
    puts "render: #{bf}.html"
  }
end