Skip to content

Commit

Permalink
Allow leading pipes to be ommitted
Browse files Browse the repository at this point in the history
  • Loading branch information
nobu committed Oct 6, 2022
1 parent 1318048 commit d263a2c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 10 deletions.
19 changes: 12 additions & 7 deletions lib/rdoc/markdown.kpeg
Expand Up @@ -1198,17 +1198,22 @@ CodeFence = &{ github? }
}

Table = &{ github? }
TableRow:header TableLine:line TableRow+:body
TableHead:header TableLine:line TableRow+:body
{ table = RDoc::Markup::Table.new(header, line, body) }

TableRow = TableItem+:row "|"? @Newline
{ row }
TableItem = "|" < (!"|" !@Newline .)+ >
TableHead = TableItem2+:items "|"? @Newline
{ items }

TableRow = ( ( TableItem:item1 TableItem2*:items { [item1, *items] } ):row | TableItem2+:row ) "|"? @Newline
{ row }
TableItem2 = "|" TableItem
TableItem = < (!"|" !@Newline .)+ >
{ text.strip }

TableLine = TableColumn+:line "|"? @Newline
{ line }
TableColumn = "|" < ( "-"+ ":"? | ":" "-"* ) >
TableLine = ( ( TableAlign:align1 TableAlign2*:aligns {[align1, *aligns] } ):line | TableAlign2+:line ) "|"? @Newline
{ line }
TableAlign2 = "|" TableAlign
TableAlign = < /:?-+:?/ >
{ text.start_with?(":") ? :left :
text.end_with?(":") ? :right : nil
}
Expand Down
6 changes: 3 additions & 3 deletions test/rdoc/test_rdoc_markdown.rb
Expand Up @@ -1065,9 +1065,9 @@ def test_gfm_table
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
------|---------|--------
|"b" | boolean | True if file1 is a block device
"c" | boolean | True if file1 is a character device
MD

head = %w[Cmd Returns Meaning]
Expand Down

0 comments on commit d263a2c

Please sign in to comment.