module CommonMarker class HtmlRenderer < Renderer def render(node) super(node) end def document(_) super if @written_footnote_ix out("\n\n") end end def header(node) block do out('", :children, '') end end def paragraph(node) if @in_tight && node.parent.type != :blockquote out(:children) else block do container("", '

') do out(:children) if node.parent.type == :footnote_definition && node.next.nil? out(" ") out_footnote_backref end end end end end def list(node) old_in_tight = @in_tight @in_tight = node.list_tight block do if node.list_type == :bullet_list container("\n", '') do out(:children) end else start = if node.list_start == 1 "\n" else "
    \n" end container(start, '
') do out(:children) end end end @in_tight = old_in_tight end def list_item(node) block do container("", '') do out(:children) end end end def blockquote(node) block do container("\n", '') do out(:children) end end end def hrule(node) block do out("") end end def code_block(node) block do if option_enabled?(:GITHUB_PRE_LANG) out("') else out("') else out('>') end end out(escape_html(node.string_content)) out('') end end def html(node) block do if option_enabled?(:SAFE) out('') else out(tagfilter(node.string_content)) end end end def inline_html(node) if option_enabled?(:SAFE) out('') else out(tagfilter(node.string_content)) end end def emph(_) out('', :children, '') end def strong(_) out('', :children, '') end def link(node) out('', :children, '') end def image(node) out('', :children, '') end def text(node) out(escape_html(node.string_content)) end def code(node) out('') out(escape_html(node.string_content)) out('') end def linebreak(node) out("
\n") end def softbreak(_) if option_enabled?(:HARDBREAKS) out("
\n") elsif option_enabled?(:NOBREAKS) out(' ') else out("\n") end end def table(node) @alignments = node.table_alignments @needs_close_tbody = false out("\n", :children) out("") if @needs_close_tbody out("\n") end def table_header(node) @column_index = 0 @in_header = true out("\n", :children, "\n\n") @in_header = false end def table_row(node) @column_index = 0 if !@in_header && !@needs_close_tbody @needs_close_tbody = true out("\n") end out("\n", :children, "\n") end def table_cell(node) align = case @alignments[@column_index] when :left; ' align="left"' when :right; ' align="right"' when :center; ' align="center"' else; '' end out(@in_header ? "\n" : "\n", :children, @in_header ? "" : "") @column_index += 1 end def strikethrough(_) out('', :children, '') end def footnote_reference(node) out("[#{node.string_content}]") end def footnote_definition(_) if !@footnote_ix out("
\n
    \n") @footnote_ix = 0 end @footnote_ix += 1 out("
  1. \n", :children) if out_footnote_backref out("\n") end out("
  2. \n") #
#
end private def out_footnote_backref return false if @written_footnote_ix == @footnote_ix @written_footnote_ix = @footnote_ix out("") true end end end