Class: ReverseMarkdown::Converters::Tr

Inherits:
Base
  • Object
show all
Defined in:
lib/reverse_markdown/converters/tr.rb

Instance Method Summary collapse

Methods inherited from Base

#escape_keychars, #extract_src, #extract_title, #treat, #treat_children

Instance Method Details

#convert(node, state = {}) ⇒ Object



4
5
6
7
8
# File 'lib/reverse_markdown/converters/tr.rb', line 4

def convert(node, state = {})
  content = treat_children(node, state).rstrip
  result  = "|#{content}\n"
  table_header_row?(node) ? result + underline_for(node) : result
end

#table_header_row?(node) ⇒ Boolean

Returns:

  • (Boolean)


10
11
12
# File 'lib/reverse_markdown/converters/tr.rb', line 10

def table_header_row?(node)
  node.element_children.all? {|child| child.name.to_sym == :th}
end

#underline_for(node) ⇒ Object



14
15
16
# File 'lib/reverse_markdown/converters/tr.rb', line 14

def underline_for(node)
  "| " + (['---'] * node.element_children.size).join(' | ') + " |\n"
end