# frozen_string_literal: true
module CommonMarker
class HtmlRenderer < Renderer
def document(_)
super
out("\n\n") if @written_footnote_ix
end
def header(node)
block do
out('
", '
') 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("')
else
out("')
else
out('>')
end
end
out(escape_html(node.string_content))
out('
')
end
end
def html(node)
block do
if option_enabled?(:UNSAFE)
out(tagfilter(node.string_content))
else
out('')
end
end
end
def inline_html(node)
if option_enabled?(:UNSAFE)
out(tagfilter(node.string_content))
else
out('')
end
end
def emph(_)
out('', :children, '')
end
def strong(_)
out('', :children, '')
end
def link(node)
out('', :children, '')
end
def image(node)
out('')
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("\n") if @needs_close_tbody
out("
\n")
end
def table_header(node)
@column_index = 0
@in_header = true
out("\n\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 then ' align="left"'
when :right then ' align="right"'
when :center then ' align="center"'
else; ''
end
out(@in_header ? "" : " ", :children, @in_header ? "\n" : " \n")
@column_index += 1
end
def strikethrough(_)
out('', :children, '')
end
def footnote_reference(node)
out("#{node.string_content}")
end
def footnote_definition(_)
unless @footnote_ix
out("\n\n")
@footnote_ix = 0
end
@footnote_ix += 1
out("- \n", :children)
out("\n") if out_footnote_backref
out("
\n")
#
#
end
private
def out_footnote_backref
return false if @written_footnote_ix == @footnote_ix
@written_footnote_ix = @footnote_ix
out("↩")
true
end
def tasklist?(node)
node.type_string == 'tasklist'
end
def checked?(node)
node.tasklist_item_checked?
end
end
end