1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

[ruby/rdoc] Support GFM table

9dc933df16
This commit is contained in:
Nobuyoshi Nakada 2021-01-26 00:31:00 +09:00
parent 05898c5b90
commit 3651f678a7
Notes: git 2021-03-16 15:47:54 +09:00
8 changed files with 471 additions and 2 deletions

View file

@ -237,6 +237,34 @@ class RDoc::Markup::ToRdoc < RDoc::Markup::Formatter
@res << "\n"
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