aboutsummaryrefslogtreecommitdiffstats
path: root/lib/rdoc/markup/table.rb
diff options
context:
space:
mode:
authorNobuyoshi Nakada <nobu@ruby-lang.org>2021-01-26 00:31:00 +0900
committerNobuyoshi Nakada <nobu@ruby-lang.org>2021-03-16 15:47:27 +0900
commit3651f678a719ae3a35825bcb4e0dabbc7c60d8df (patch)
treef8705c06212e4778780c1db52b99ae17d319e33d /lib/rdoc/markup/table.rb
parent05898c5b9001c0b1e8bd7bf0d12b42a8e7c388b8 (diff)
downloadruby-3651f678a719ae3a35825bcb4e0dabbc7c60d8df.tar.gz
[ruby/rdoc] Support GFM table
https://github.com/ruby/rdoc/commit/9dc933df16
Diffstat (limited to 'lib/rdoc/markup/table.rb')
-rw-r--r--lib/rdoc/markup/table.rb47
1 files changed, 47 insertions, 0 deletions
diff --git a/lib/rdoc/markup/table.rb b/lib/rdoc/markup/table.rb
new file mode 100644
index 0000000000..7bcb10aff3
--- /dev/null
+++ b/lib/rdoc/markup/table.rb
@@ -0,0 +1,47 @@
+# frozen_string_literal: true
+##
+# A section of table
+
+class RDoc::Markup::Table
+ attr_accessor :header, :align, :body
+
+ def initialize header, align, body
+ @header, @align, @body = header, align, body
+ end
+
+ def == other
+ self.class == other.class and
+ @header == other.header and
+ @align == other.align and
+ @body == other.body
+ end
+
+ def accept visitor
+ visitor.accept_table @header, @body, @align
+ end
+
+ def pretty_print q # :nodoc:
+ q.group 2, '[Table: ', ']' do
+ q.group 2, '[Head: ', ']' do
+ q.seplist @header.zip(@align) do |text, align|
+ q.pp text
+ if align
+ q.text ":"
+ q.breakable
+ q.text align.to_s
+ end
+ end
+ end
+ q.breakable
+ q.group 2, '[Body: ', ']' do
+ q.seplist @body do |body|
+ q.group 2, '[', ']' do
+ q.seplist body do |text|
+ q.pp text
+ end
+ end
+ end
+ end
+ end
+ end
+end