diff options
author | Nobuyoshi Nakada <[email protected]> | 2021-01-26 00:31:00 +0900 |
---|---|---|
committer | Nobuyoshi Nakada <[email protected]> | 2021-03-16 15:47:27 +0900 |
commit | 3651f678a719ae3a35825bcb4e0dabbc7c60d8df (patch) | |
tree | f8705c06212e4778780c1db52b99ae17d319e33d /lib/rdoc/markup/to_rdoc.rb | |
parent | 05898c5b9001c0b1e8bd7bf0d12b42a8e7c388b8 (diff) |
[ruby/rdoc] Support GFM table
https://github.com/ruby/rdoc/commit/9dc933df16
Notes
Notes:
Merged: https://github.com/ruby/ruby/pull/4274
Diffstat (limited to 'lib/rdoc/markup/to_rdoc.rb')
-rw-r--r-- | lib/rdoc/markup/to_rdoc.rb | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/lib/rdoc/markup/to_rdoc.rb b/lib/rdoc/markup/to_rdoc.rb index 81b16c4973..3cdf4fd08b 100644 --- a/lib/rdoc/markup/to_rdoc.rb +++ b/lib/rdoc/markup/to_rdoc.rb @@ -238,6 +238,34 @@ class RDoc::Markup::ToRdoc < RDoc::Markup::Formatter end ## + # Adds +table+ to the output + + def accept_table header, body, aligns + widths = header.zip(body) do |h, b| + [h.size, b.size].max + end + aligns = aligns.map do |a| + case a + when nil + :center + when :left + :ljust + when :right + :rjust + end + end + @res << header.zip(widths, aligns) do |h, w, a| + h.__send__(a, w) + end.join("|").rstrip << "\n" + @res << widths.map {|w| "-" * w }.join("|") << "\n" + body.each do |row| + @res << row.zip(widths, aligns) do |t, w, a| + t.__send__(a, w) + end.join("|").rstrip << "\n" + end + end + + ## # Applies attribute-specific markup to +text+ using RDoc::AttributeManager def attributes text |