Class: GfmToBlockkit::Converters::Table::Preformatted
- Defined in:
- lib/gfm_to_blockkit/converters/table/preformatted.rb
Instance Method Summary collapse
Methods inherited from Base
converter_for, handles, #initialize, #render_child_as_elements
Constructor Details
This class inherits a constructor from GfmToBlockkit::Converters::Base
Instance Method Details
#convert(node) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/gfm_to_blockkit/converters/table/preformatted.rb', line 7 def convert(node) rows = extract_rows(node) return [] if rows.empty? alignments = extract_alignments(node, rows.first.length) widths = compute_column_widths(rows) lines = [] rows.each_with_index do |row, i| lines << format_row(row, widths, alignments) lines << separator_row(widths, alignments) if i == 0 end ascii = lines.join("\n") [{ type: "rich_text", elements: [{ type: "rich_text_preformatted", elements: [{type: "text", text: ascii}], border: 0 }] }] end |