class Muwu::RenderMarkupToHtml

Public Class Methods

new(project) click to toggle source
# File lib/muwu/render_html/render_markup_to_html.rb, line 13
def initialize(project)
  @project = project
end

Public Instance Methods

render(filename) click to toggle source
# File lib/muwu/render_html/render_markup_to_html.rb, line 22
def render(filename)
  case File.extname(filename).downcase
  when '.md'
    render_md(filename)
  when '.haml'
    render_haml(filename)
  end
end

Private Instance Methods

read_haml_text(filename) click to toggle source
# File lib/muwu/render_html/render_markup_to_html.rb, line 36
def read_haml_text(filename)
  File.read(filename)
end
read_markdown_text(filename) click to toggle source
# File lib/muwu/render_html/render_markup_to_html.rb, line 41
def read_markdown_text(filename)
  if @project.options.markdown_allows_raw_html == true
    File.read(filename)
  else
    CGI.escapeHTML(File.read(filename))
  end
end
render_haml(filename) click to toggle source
# File lib/muwu/render_html/render_markup_to_html.rb, line 50
def render_haml(filename)
  text = read_haml_text(filename)
  Haml::Engine.new(text, {suppress_eval: true}).render
end
render_md(filename) click to toggle source
# File lib/muwu/render_html/render_markup_to_html.rb, line 56
def render_md(filename)
  text = read_markdown_text(filename)
  case @project.options.markdown_renderer
  when 'commonmarker'
    render_md_commonmarker(text)
  when 'motion-markdown-it'
    render_md_motion_markdown_it(text)
  end
end
render_md_commonmarker(text) click to toggle source
# File lib/muwu/render_html/render_markup_to_html.rb, line 67
def render_md_commonmarker(text)
  if @project.options.render_punctuation_smart
    CommonMarker.render_doc(text, :SMART).to_html
  else
    CommonMarker.render_doc(text, :DEFAULT).to_html
  end
end
render_md_motion_markdown_it(text) click to toggle source
# File lib/muwu/render_html/render_markup_to_html.rb, line 76
def render_md_motion_markdown_it(text)
  if @project.options.render_punctuation_smart
    MarkdownIt::Parser.new({html: true, typographer: true}).use(Muwu::Var::MotionMarkdownItPlugins::Deflistdiv).render(text)
  else
    MarkdownIt::Parser.new({html: true}).use(Muwu::Var::MotionMarkdownItPlugins::Deflistdiv).render(text)
  end
end