[ruby/rdoc] Allow escaped pipes in cells

https://github.com/ruby/rdoc/commit/333952a62d
This commit is contained in:
Nobuyoshi Nakada 2022-10-06 17:26:21 +09:00
Родитель f6c916c7ef
Коммит 7c03c82444
2 изменённых файлов: 21 добавлений и 69 удалений

Просмотреть файл

@ -16132,73 +16132,13 @@ class RDoc::Markdown
return _tmp
end
# TableItem = < (!"|" !@Newline .)+ > { text.strip }
# TableItem = < /(?:\\.|[^|\n])+/ > { text.strip.gsub(/\\(.)/, '\1') }
def _TableItem
_save = self.pos
while true # sequence
_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
_tmp = scan(/\G(?-mix:(?:\\.|[^|\n])+)/)
if _tmp
text = get_text(_text_start)
end
@ -16206,7 +16146,7 @@ class RDoc::Markdown
self.pos = _save
break
end
@result = begin; text.strip ; end
@result = begin; text.strip.gsub(/\\(.)/, '\1') ; end
_tmp = true
unless _tmp
self.pos = _save
@ -16311,7 +16251,7 @@ class RDoc::Markdown
return _tmp
end
# TableAlign2 = "|" TableAlign
# TableAlign2 = "|" @Sp TableAlign
def _TableAlign2
_save = self.pos
@ -16321,6 +16261,11 @@ class RDoc::Markdown
self.pos = _save
break
end
_tmp = _Sp()
unless _tmp
self.pos = _save
break
end
_tmp = apply(:_TableAlign)
unless _tmp
self.pos = _save
@ -16332,7 +16277,7 @@ class RDoc::Markdown
return _tmp
end
# TableAlign = < /:?-+:?/ > { text.start_with?(":") ? :left : text.end_with?(":") ? :right : nil }
# TableAlign = < /:?-+:?/ > @Sp { text.start_with?(":") ? :left : text.end_with?(":") ? :right : nil }
def _TableAlign
_save = self.pos
@ -16346,6 +16291,11 @@ class RDoc::Markdown
self.pos = _save
break
end
_tmp = _Sp()
unless _tmp
self.pos = _save
break
end
@result = begin; text.start_with?(":") ? :left :
text.end_with?(":") ? :right : nil
; end
@ -16796,10 +16746,10 @@ class RDoc::Markdown
Rules[:_TableHead] = rule_info("TableHead", "TableItem2+:items \"|\"? @Newline { items }")
Rules[:_TableRow] = rule_info("TableRow", "((TableItem:item1 TableItem2*:items { [item1, *items] }):row | TableItem2+:row) \"|\"? @Newline { row }")
Rules[:_TableItem2] = rule_info("TableItem2", "\"|\" TableItem")
Rules[:_TableItem] = rule_info("TableItem", "< (!\"|\" !@Newline .)+ > { text.strip }")
Rules[:_TableItem] = rule_info("TableItem", "< /(?:\\\\.|[^|\\n])+/ > { text.strip.gsub(/\\\\(.)/, '\\1') }")
Rules[:_TableLine] = rule_info("TableLine", "((TableAlign:align1 TableAlign2*:aligns {[align1, *aligns] }):line | TableAlign2+:line) \"|\"? @Newline { line }")
Rules[:_TableAlign2] = rule_info("TableAlign2", "\"|\" TableAlign")
Rules[:_TableAlign] = rule_info("TableAlign", "< /:?-+:?/ > { text.start_with?(\":\") ? :left : text.end_with?(\":\") ? :right : nil }")
Rules[:_TableAlign2] = rule_info("TableAlign2", "\"|\" @Sp TableAlign")
Rules[:_TableAlign] = rule_info("TableAlign", "< /:?-+:?/ > @Sp { 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 }")
Rules[:_DefinitionListLabel] = rule_info("DefinitionListLabel", "StrChunk:label @Sp @Newline { label }")

Просмотреть файл

@ -1063,11 +1063,12 @@ and an extra note.[^2]
end
def test_gfm_table_2
doc = parse <<~MD
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]
@ -1075,6 +1076,7 @@ and an extra note.[^2]
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))