Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More compliant with GFM table #931

Merged
merged 5 commits into from
Oct 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 18 additions & 11 deletions lib/rdoc/markdown.kpeg
Original file line number Diff line number Diff line change
Expand Up @@ -1198,19 +1198,26 @@ 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 .)+ >
{ text.strip }

TableLine = TableColumn+:line "|" @Newline
{ line }
TableColumn = "|" < ( "-"+ ":"? | ":" "-"* ) >
{ text.start_with?(":") ? :left :
text.end_with?(":") ? :right : nil
TableHead = TableItem2+:items "|"? @Newline
{ items }

TableRow = ( ( TableItem:item1 TableItem2*:items { [item1, *items] } ):row | TableItem2+:row ) "|"? @Newline
{ row }
TableItem2 = "|" TableItem
TableItem = < /(?:\\.|[^|\n])+/ >
{ text.strip.gsub(/\\(.)/, '\1') }

TableLine = ( ( TableAlign:align1 TableAlign2*:aligns {[align1, *aligns] } ):line | TableAlign2+:line ) "|"? @Newline
{ line }
TableAlign2 = "|" @Sp TableAlign
TableAlign = < /:?-+:?/ > @Sp
{
text.start_with?(":") ?
(text.end_with?(":") ? :center : :left) :
(text.end_with?(":") ? :right : nil)
}

DefinitionList = &{ definition_lists? }
Expand Down
21 changes: 21 additions & 0 deletions test/rdoc/test_rdoc_markdown.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1062,6 +1062,27 @@ def test_gfm_table
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
|"\|" | boolean | escaped bar \| test
MD

head = %w[Cmd Returns Meaning]
align = [nil, :center, nil]
body = [
['"b"', 'boolean', 'True if file1 is a block device'],
['"c"', 'boolean', 'True if file1 is a character device'],
['"|"', 'boolean', 'escaped bar | test'],
]
expected = doc(@RM::Table.new(head, align, body))

assert_equal expected, doc
end

def parse text
@parser.parse text
end
Expand Down