ruby-changes:65574
From: Nobuyoshi <ko1@a...>
Date: Tue, 16 Mar 2021 15:47:45 +0900 (JST)
Subject: [ruby-changes:65574] 3651f678a7 (master): [ruby/rdoc] Support GFM table
https://git.ruby-lang.org/ruby.git/commit/?id=3651f678a7 From 3651f678a719ae3a35825bcb4e0dabbc7c60d8df Mon Sep 17 00:00:00 2001 From: Nobuyoshi Nakada <nobu@r...> Date: Tue, 26 Jan 2021 00:31:00 +0900 Subject: [ruby/rdoc] Support GFM table https://github.com/ruby/rdoc/commit/9dc933df16 --- lib/rdoc/markdown.rb | 349 +++++++++++++++++++++++++++++++- lib/rdoc/markup.rb | 1 + lib/rdoc/markup/table.rb | 47 +++++ lib/rdoc/markup/to_html.rb | 23 +++ lib/rdoc/markup/to_joined_paragraph.rb | 1 + lib/rdoc/markup/to_rdoc.rb | 28 +++ lib/rdoc/markup/to_table_of_contents.rb | 1 + test/rdoc/test_rdoc_markdown.rb | 23 +++ 8 files changed, 471 insertions(+), 2 deletions(-) create mode 100644 lib/rdoc/markup/table.rb diff --git a/lib/rdoc/markdown.rb b/lib/rdoc/markdown.rb index 903e7441..d9bfbd3 100644 --- a/lib/rdoc/markdown.rb +++ b/lib/rdoc/markdown.rb @@ -897,7 +897,7 @@ class RDoc::Markdown https://github.com/ruby/ruby/blob/trunk/lib/rdoc/markdown.rb#L897 return _tmp end - # Block = @BlankLine* (BlockQuote | Verbatim | CodeFence | Note | Reference | HorizontalRule | Heading | OrderedList | BulletList | DefinitionList | HtmlBlock | StyleBlock | Para | Plain) + # Block = @BlankLine* (BlockQuote | Verbatim | CodeFence | Table | Note | Reference | HorizontalRule | Heading | OrderedList | BulletList | DefinitionList | HtmlBlock | StyleBlock | Para | Plain) def _Block _save = self.pos @@ -923,6 +923,9 @@ class RDoc::Markdown https://github.com/ruby/ruby/blob/trunk/lib/rdoc/markdown.rb#L923 _tmp = apply(:_CodeFence) break if _tmp self.pos = _save2 + _tmp = apply(:_Table) + break if _tmp + self.pos = _save2 _tmp = apply(:_Note) break if _tmp self.pos = _save2 @@ -15847,6 +15850,343 @@ class RDoc::Markdown https://github.com/ruby/ruby/blob/trunk/lib/rdoc/markdown.rb#L15850 return _tmp end + # Table = &{ github? } TableRow:header TableLine:line TableRow+:body { table = RDoc::Markup::Table.new(header, line, body) } + def _Table + + _save = self.pos + while true # sequence + _save1 = self.pos + _tmp = begin; github? ; end + self.pos = _save1 + unless _tmp + self.pos = _save + break + end + _tmp = apply(:_TableRow) + header = @result + unless _tmp + self.pos = _save + break + end + _tmp = apply(:_TableLine) + line = @result + unless _tmp + self.pos = _save + break + end + _save2 = self.pos + _ary = [] + _tmp = apply(:_TableRow) + if _tmp + _ary << @result + while true + _tmp = apply(:_TableRow) + _ary << @result if _tmp + break unless _tmp + end + _tmp = true + @result = _ary + else + self.pos = _save2 + end + body = @result + unless _tmp + self.pos = _save + break + end + @result = begin; table = RDoc::Markup::Table.new(header, line, body) ; end + _tmp = true + unless _tmp + self.pos = _save + end + break + end # end sequence + + set_failed_rule :_Table unless _tmp + return _tmp + end + + # TableRow = < TableItem+:row > "|" @Newline { row } + def _TableRow + + _save = self.pos + while true # sequence + _text_start = self.pos + _save1 = self.pos + _ary = [] + _tmp = apply(:_TableItem) + if _tmp + _ary << @result + while true + _tmp = apply(:_TableItem) + _ary << @result if _tmp + break unless _tmp + end + _tmp = true + @result = _ary + else + self.pos = _save1 + end + row = @result + if _tmp + text = get_text(_text_start) + end + unless _tmp + self.pos = _save + break + end + _tmp = match_string("|") + unless _tmp + self.pos = _save + break + end + _tmp = _Newline() + unless _tmp + self.pos = _save + break + end + @result = begin; row ; end + _tmp = true + unless _tmp + self.pos = _save + end + break + end # end sequence + + set_failed_rule :_TableRow unless _tmp + return _tmp + end + + # TableItem = "|" < (!"|" !@Newline .)+ > { text.strip } + def _TableItem + + _save = self.pos + while true # sequence + _tmp = match_string("|") + unless _tmp + self.pos = _save + break + end + _text_start = self.pos + _save1 = self.pos + + _save2 = self.pos + while true # sequence + _save3 = self.pos + _tmp = match_string("|") + _tmp = _tmp ? nil : true + self.pos = _save3 + unless _tmp + self.pos = _save2 + break + end + _save4 = self.pos + _tmp = _Newline() + _tmp = _tmp ? nil : true + self.pos = _save4 + unless _tmp + self.pos = _save2 + break + end + _tmp = get_byte + unless _tmp + self.pos = _save2 + end + break + end # end sequence + + if _tmp + while true + + _save5 = self.pos + while true # sequence + _save6 = self.pos + _tmp = match_string("|") + _tmp = _tmp ? nil : true + self.pos = _save6 + unless _tmp + self.pos = _save5 + break + end + _save7 = self.pos + _tmp = _Newline() + _tmp = _tmp ? nil : true + self.pos = _save7 + unless _tmp + self.pos = _save5 + break + end + _tmp = get_byte + unless _tmp + self.pos = _save5 + end + break + end # end sequence + + break unless _tmp + end + _tmp = true + else + self.pos = _save1 + end + if _tmp + text = get_text(_text_start) + end + unless _tmp + self.pos = _save + break + end + @result = begin; text.strip ; end + _tmp = true + unless _tmp + self.pos = _save + end + break + end # end sequence + + set_failed_rule :_TableItem unless _tmp + return _tmp + end + + # TableLine = TableColumn+:line "|" @Newline { line } + def _TableLine + + _save = self.pos + while true # sequence + _save1 = self.pos + _ary = [] + _tmp = apply(:_TableColumn) + if _tmp + _ary << @result + while true + _tmp = apply(:_TableColumn) + _ary << @result if _tmp + break unless _tmp + end + _tmp = true + @result = _ary + else + self.pos = _save1 + end + line = @result + unless _tmp + self.pos = _save + break + end + _tmp = match_string("|") + unless _tmp + self.pos = _save + break + end + _tmp = _Newline() + unless _tmp + self.pos = _save + break + end + @result = begin; line ; end + _tmp = true + unless _tmp + self.pos = _save + end + break + end # end sequence + + set_failed_rule :_TableLine unless _tmp + return _tmp + end + + # TableColumn = "|" < ("-"+ ":"? | ":" "-"*) > { text.start_with?(":") ? :left : text.end_with?(":") ? :right : nil } + def _TableColumn + + _save = self.pos + while true # sequence + _tmp = match_string("|") + unless _tmp + self.pos = _save + break + end + _text_start = self.pos + + _save1 = self.pos + while true # choice + + _save2 = self.pos + while true # sequence + _save3 = self.pos + _tmp = match_string("-") + if _tmp + while true + _tmp = match_string("-") + break unless _tmp + end + _tmp = true + else + self.pos = _save3 + end + unless _tmp + self.pos = _save2 + break + end + _save4 = self.pos + _tmp = match_string(":") + unless _tmp + _tmp = true + self.pos = _save4 + end + unless _tmp + self.pos = _save2 + end + break + end # end sequence + + break if _tmp + self.pos = _save1 + + _save5 = self.pos + while true # sequence + _tmp = match_string(":") + unless _tmp + self.pos = _save5 + break + end + while true + _tmp = match_string("-") + break unless _tmp + end + _tmp = true + unless _tmp + self.pos = _save5 + end + break + end # end sequence + + break if _tmp + self.pos = _save1 + break + end # end choice + + if _tmp + text = get_text(_text_start) + end + unless _tmp + self.pos = _save + break + end + @result = begin; + text.start_with?(":") ? :left : + text.end_with?(":") ? :right : nil + ; end + _tmp = true + unless _tmp + self.pos = _save + end + break + end # end sequence + + set_failed_rule :_TableColumn unless _tmp + return _tmp + end + # DefinitionList = &{ definition_lists? } DefinitionListItem+:list { RDoc::Markup::List.new :NOTE, *list.flatten } def _DefinitionList @@ -16046,7 +16386,7 @@ class RDoc::Markdown https://github.com/ruby/ruby/blob/trunk/lib/rdoc/markdown.rb#L16386 Rules = {} Rules[:_root] = rule_info("root", "Doc") Rules[:_Doc] = rule_info("Doc", "BOM? Block*:a { RDoc::Markup::Document.new(*a.compact) }") - Rules[:_Block] = rule_ (... truncated) -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/