[前][次][番号順一覧][スレッド一覧]

ruby-changes:73877

From: Nobuyoshi <ko1@a...>
Date: Thu, 6 Oct 2022 23:23:32 +0900 (JST)
Subject: [ruby-changes:73877] a19bf47d03 (master): [ruby/rdoc] Allow trailing pipes to be ommitted

https://git.ruby-lang.org/ruby.git/commit/?id=a19bf47d03

From a19bf47d03b51b339688c865c35bff0c0d2be6c1 Mon Sep 17 00:00:00 2001
From: Nobuyoshi Nakada <nobu@r...>
Date: Thu, 6 Oct 2022 13:10:31 +0900
Subject: [ruby/rdoc] Allow trailing pipes to be ommitted

https://github.com/ruby/rdoc/commit/1318048877
---
 lib/rdoc/markdown.rb            | 18 ++++++++++++++----
 test/rdoc/test_rdoc_markdown.rb | 19 +++++++++++++++++++
 2 files changed, 33 insertions(+), 4 deletions(-)

diff --git a/lib/rdoc/markdown.rb b/lib/rdoc/markdown.rb
index 26b32f9b73..1149359927 100644
--- a/lib/rdoc/markdown.rb
+++ b/lib/rdoc/markdown.rb
@@ -15966,7 +15966,7 @@ class RDoc::Markdown https://github.com/ruby/ruby/blob/trunk/lib/rdoc/markdown.rb#L15966
     return _tmp
   end
 
-  # TableRow = TableItem+:row "|" @Newline { row }
+  # TableRow = TableItem+:row "|"? @Newline { row }
   def _TableRow
 
     _save = self.pos
@@ -15991,7 +15991,12 @@ class RDoc::Markdown https://github.com/ruby/ruby/blob/trunk/lib/rdoc/markdown.rb#L15991
         self.pos = _save
         break
       end
+      _save2 = self.pos
       _tmp = match_string("|")
+      unless _tmp
+        _tmp = true
+        self.pos = _save2
+      end
       unless _tmp
         self.pos = _save
         break
@@ -16104,7 +16109,7 @@ class RDoc::Markdown https://github.com/ruby/ruby/blob/trunk/lib/rdoc/markdown.rb#L16109
     return _tmp
   end
 
-  # TableLine = TableColumn+:line "|" @Newline { line }
+  # TableLine = TableColumn+:line "|"? @Newline { line }
   def _TableLine
 
     _save = self.pos
@@ -16129,7 +16134,12 @@ class RDoc::Markdown https://github.com/ruby/ruby/blob/trunk/lib/rdoc/markdown.rb#L16134
         self.pos = _save
         break
       end
+      _save2 = self.pos
       _tmp = match_string("|")
+      unless _tmp
+        _tmp = true
+        self.pos = _save2
+      end
       unless _tmp
         self.pos = _save
         break
@@ -16675,9 +16685,9 @@ class RDoc::Markdown https://github.com/ruby/ruby/blob/trunk/lib/rdoc/markdown.rb#L16685
   Rules[:_RawNoteBlock] = rule_info("RawNoteBlock", "@StartList:a (!@BlankLine !RawNoteReference OptionallyIndentedLine:l { a << l })+ < @BlankLine* > { a << text } { a }")
   Rules[:_CodeFence] = rule_info("CodeFence", "&{ github? } Ticks3 (@Sp StrChunk:format)? Spnl < ((!\"`\" Nonspacechar)+ | !Ticks3 /`+/ | Spacechar | @Newline)+ > Ticks3 @Sp @Newline* { verbatim = RDoc::Markup::Verbatim.new text               verbatim.format = format.intern if format.instance_of?(String)               verbatim             }")
   Rules[:_Table] = rule_info("Table", "&{ github? } TableRow:header TableLine:line TableRow+:body { table = RDoc::Markup::Table.new(header, line, body) }")
-  Rules[:_TableRow] = rule_info("TableRow", "TableItem+:row \"|\" @Newline { row }")
+  Rules[:_TableRow] = rule_info("TableRow", "TableItem+:row \"|\"? @Newline { row }")
   Rules[:_TableItem] = rule_info("TableItem", "\"|\" < (!\"|\" !@Newline .)+ > { text.strip }")
-  Rules[:_TableLine] = rule_info("TableLine", "TableColumn+:line \"|\" @Newline { line }")
+  Rules[:_TableLine] = rule_info("TableLine", "TableColumn+:line \"|\"? @Newline { line }")
   Rules[:_TableColumn] = rule_info("TableColumn", "\"|\" < (\"-\"+ \":\"? | \":\" \"-\"*) > { text.start_with?(\":\") ? :left :                 text.end_with?(\":\") ? :right : nil               }")
   Rules[:_DefinitionList] = rule_info("DefinitionList", "&{ definition_lists? } DefinitionListItem+:list { RDoc::Markup::List.new :NOTE, *list.flatten }")
   Rules[:_DefinitionListItem] = rule_info("DefinitionListItem", "DefinitionListLabel+:label DefinitionListDefinition+:defns { list_items = []                        list_items <<                          RDoc::Markup::ListItem.new(label, defns.shift)                         list_items.concat defns.map { |defn|                          RDoc::Markup::ListItem.new nil, defn                        } unless list_items.empty?                         list_items                      }")
diff --git a/test/rdoc/test_rdoc_markdown.rb b/test/rdoc/test_rdoc_markdown.rb
index ca76c34f43..4c45794343 100644
--- a/test/rdoc/test_rdoc_markdown.rb
+++ b/test/rdoc/test_rdoc_markdown.rb
@@ -1062,6 +1062,25 @@ and an extra note.[^2] https://github.com/ruby/ruby/blob/trunk/test/rdoc/test_rdoc_markdown.rb#L1062
     assert_equal expected, doc
   end
 
+  def test_gfm_table_2
+    doc = parse <<~MD
+    | Cmd | Returns | Meaning
+    |-----|---------|--------
+    | "b" | boolean | True if file1 is a block device
+    | "c" | boolean | True if file1 is a character device
+    MD
+
+    head = %w[Cmd Returns Meaning]
+    align = [nil, nil, nil]
+    body = [
+      ['"b"', 'boolean', 'True if file1 is a block device'],
+      ['"c"', 'boolean', 'True if file1 is a character device'],
+    ]
+    expected = doc(@RM::Table.new(head, align, body))
+
+    assert_equal expected, doc
+  end
+
   def parse text
     @parser.parse text
   end
-- 
cgit v1.2.1


--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]