diff --git a/lib/rdoc/generator/template/darkfish/css/rdoc.css b/lib/rdoc/generator/template/darkfish/css/rdoc.css index 35aff77fcb..221550a051 100644 --- a/lib/rdoc/generator/template/darkfish/css/rdoc.css +++ b/lib/rdoc/generator/template/darkfish/css/rdoc.css @@ -79,6 +79,25 @@ pre { border-radius: 0.2em; } +table { + margin: 0; + border-spacing: 0; + border-collapse: collapse; +} + +table tr th, table tr td { + padding: 0.2em 0.4em; + border: 1px solid #ccc; +} + +table tr th { + background-color: #eceaed; +} + +table tr:nth-child(even) td { + background-color: #f5f4f6; +} + /* @group Generic Classes */ .initially-hidden { diff --git a/lib/rdoc/markdown.kpeg b/lib/rdoc/markdown.kpeg index 8b78cdd114..6717cce132 100644 --- a/lib/rdoc/markdown.kpeg +++ b/lib/rdoc/markdown.kpeg @@ -506,6 +506,7 @@ Block = @BlankLine* ( BlockQuote | Verbatim | CodeFence + | Table | Note | Reference | HorizontalRule @@ -1195,6 +1196,23 @@ CodeFence = &{ github? } verbatim } +Table = &{ github? } + TableRow:header TableLine:line TableRow+:body + { table = RDoc::Markup::Table.new(header, line, body) } + +TableRow = < TableItem+:row > "|" @Newline + { row } +TableItem = "|" < (!"|" !@Newline .)+ > + { text.strip } + +TableLine = TableColumn+:line "|" @Newline + { line } +TableColumn = "|" < ( "-"+ ":"? | ":" "-"* ) > + { + text.start_with?(":") ? :left : + text.end_with?(":") ? :right : nil + } + DefinitionList = &{ definition_lists? } ( DefinitionListItem+:list ) { RDoc::Markup::List.new :NOTE, *list.flatten } diff --git a/lib/rdoc/markup.rb b/lib/rdoc/markup.rb index fd59fca314..92aed757cf 100644 --- a/lib/rdoc/markup.rb +++ b/lib/rdoc/markup.rb @@ -843,6 +843,7 @@ def convert input, formatter autoload :List, 'rdoc/markup/list' autoload :ListItem, 'rdoc/markup/list_item' autoload :Paragraph, 'rdoc/markup/paragraph' + autoload :Table, 'rdoc/markup/table' autoload :Raw, 'rdoc/markup/raw' autoload :Rule, 'rdoc/markup/rule' autoload :Verbatim, 'rdoc/markup/verbatim' 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 diff --git a/lib/rdoc/markup/to_html.rb b/lib/rdoc/markup/to_html.rb index 3b1b0e9d40..e2a00bd8a1 100644 --- a/lib/rdoc/markup/to_html.rb +++ b/lib/rdoc/markup/to_html.rb @@ -314,6 +314,29 @@ def accept_raw raw @res << raw.parts.join("\n") end + ## + # Adds +table+ to the output + + def accept_table header, body, aligns + @res << "\n
' << CGI.escapeHTML(text) << " | \n" + end + @res << "
---|
' << CGI.escapeHTML(text) << " | \n" + end + @res << "