Class: DocsKit::MarkdownExport::Table

Inherits:
Object
  • Object
show all
Defined in:
lib/docs_kit/markdown_export/table.rb

Overview

A GFM pipe table. The first row (thead, or the first row if there's no thead) is the header; a separator row follows; the rest are body rows. Cell content is inline Markdown with pipes escaped so they don't break the table.

Instance Method Summary collapse

Constructor Details

#initialize(export) ⇒ Table

Returns a new instance of Table.



9
10
11
# File 'lib/docs_kit/markdown_export/table.rb', line 9

def initialize(export)
  @inline = Inline.new(export)
end

Instance Method Details

#render(node) ⇒ Object



13
14
15
16
17
18
19
20
21
22
# File 'lib/docs_kit/markdown_export/table.rb', line 13

def render(node)
  rows = rows(node)
  return "" if rows.empty?

  width = rows.map(&:length).max
  header, *body = pad(rows, width)
  lines = [row(header), separator(width)]
  lines.concat(body.map { |cells| row(cells) })
  lines.join("\n")
end