Skip to content

Commit c8308eb

Browse files
authored
Merge pull request #931 from nobu/GFM-table
More compliant with GFM table
2 parents b76775f + 512cc55 commit c8308eb

File tree

2 files changed

+39
-11
lines changed

2 files changed

+39
-11
lines changed

lib/rdoc/markdown.kpeg

+18-11
Original file line numberDiff line numberDiff line change
@@ -1198,19 +1198,26 @@ CodeFence = &{ github? }
11981198
}
11991199

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

1204-
TableRow = TableItem+:row "|" @Newline
1205-
{ row }
1206-
TableItem = "|" < (!"|" !@Newline .)+ >
1207-
{ text.strip }
1208-
1209-
TableLine = TableColumn+:line "|" @Newline
1210-
{ line }
1211-
TableColumn = "|" < ( "-"+ ":"? | ":" "-"* ) >
1212-
{ text.start_with?(":") ? :left :
1213-
text.end_with?(":") ? :right : nil
1204+
TableHead = TableItem2+:items "|"? @Newline
1205+
{ items }
1206+
1207+
TableRow = ( ( TableItem:item1 TableItem2*:items { [item1, *items] } ):row | TableItem2+:row ) "|"? @Newline
1208+
{ row }
1209+
TableItem2 = "|" TableItem
1210+
TableItem = < /(?:\\.|[^|\n])+/ >
1211+
{ text.strip.gsub(/\\(.)/, '\1') }
1212+
1213+
TableLine = ( ( TableAlign:align1 TableAlign2*:aligns {[align1, *aligns] } ):line | TableAlign2+:line ) "|"? @Newline
1214+
{ line }
1215+
TableAlign2 = "|" @Sp TableAlign
1216+
TableAlign = < /:?-+:?/ > @Sp
1217+
{
1218+
text.start_with?(":") ?
1219+
(text.end_with?(":") ? :center : :left) :
1220+
(text.end_with?(":") ? :right : nil)
12141221
}
12151222

12161223
DefinitionList = &{ definition_lists? }

test/rdoc/test_rdoc_markdown.rb

+21
Original file line numberDiff line numberDiff line change
@@ -1062,6 +1062,27 @@ def test_gfm_table
10621062
assert_equal expected, doc
10631063
end
10641064

1065+
def test_gfm_table_2
1066+
doc = parse <<~'MD'
1067+
| Cmd | Returns | Meaning
1068+
----- | :-----: | -------
1069+
|"b" | boolean | True if file1 is a block device
1070+
"c" | boolean | True if file1 is a character device
1071+
|"\|" | boolean | escaped bar \| test
1072+
MD
1073+
1074+
head = %w[Cmd Returns Meaning]
1075+
align = [nil, :center, nil]
1076+
body = [
1077+
['"b"', 'boolean', 'True if file1 is a block device'],
1078+
['"c"', 'boolean', 'True if file1 is a character device'],
1079+
['"|"', 'boolean', 'escaped bar | test'],
1080+
]
1081+
expected = doc(@RM::Table.new(head, align, body))
1082+
1083+
assert_equal expected, doc
1084+
end
1085+
10651086
def parse text
10661087
@parser.parse text
10671088
end

0 commit comments

Comments
 (0)