1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

[ruby/rdoc] Add center align

https://github.com/ruby/rdoc/commit/512cc55a0e
This commit is contained in:
Nobuyoshi Nakada 2022-10-06 17:39:10 +09:00
parent 28e24ce355
commit cf3056be69
2 changed files with 12 additions and 70 deletions

View file

@ -16132,73 +16132,13 @@ class RDoc::Markdown
return _tmp return _tmp
end end
# TableItem = < (!"|" !@Newline .)+ > { text.strip } # TableItem = < /(?:\\.|[^|\n])+/ > { text.strip.gsub(/\\(.)/, '\1') }
def _TableItem def _TableItem
_save = self.pos _save = self.pos
while true # sequence while true # sequence
_text_start = self.pos _text_start = self.pos
_save1 = self.pos _tmp = scan(/\G(?-mix:(?:\\.|[^|\n])+)/)
_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
if _tmp if _tmp
text = get_text(_text_start) text = get_text(_text_start)
end end
@ -16206,7 +16146,7 @@ class RDoc::Markdown
self.pos = _save self.pos = _save
break break
end end
@result = begin; text.strip ; end @result = begin; text.strip.gsub(/\\(.)/, '\1') ; end
_tmp = true _tmp = true
unless _tmp unless _tmp
self.pos = _save self.pos = _save
@ -16337,7 +16277,7 @@ class RDoc::Markdown
return _tmp return _tmp
end end
# TableAlign = < /:?-+:?/ > @Sp { text.start_with?(":") ? :left : text.end_with?(":") ? :right : nil } # TableAlign = < /:?-+:?/ > @Sp { text.start_with?(":") ? (text.end_with?(":") ? :center : :left) : (text.end_with?(":") ? :right : nil) }
def _TableAlign def _TableAlign
_save = self.pos _save = self.pos
@ -16356,8 +16296,10 @@ class RDoc::Markdown
self.pos = _save self.pos = _save
break break
end end
@result = begin; text.start_with?(":") ? :left : @result = begin;
text.end_with?(":") ? :right : nil text.start_with?(":") ?
(text.end_with?(":") ? :center : :left) :
(text.end_with?(":") ? :right : nil)
; end ; end
_tmp = true _tmp = true
unless _tmp unless _tmp
@ -16806,10 +16748,10 @@ class RDoc::Markdown
Rules[:_TableHead] = rule_info("TableHead", "TableItem2+:items \"|\"? @Newline { items }") 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[:_TableRow] = rule_info("TableRow", "((TableItem:item1 TableItem2*:items { [item1, *items] }):row | TableItem2+:row) \"|\"? @Newline { row }")
Rules[:_TableItem2] = rule_info("TableItem2", "\"|\" TableItem") 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[:_TableLine] = rule_info("TableLine", "((TableAlign:align1 TableAlign2*:aligns {[align1, *aligns] }):line | TableAlign2+:line) \"|\"? @Newline { line }")
Rules[:_TableAlign2] = rule_info("TableAlign2", "\"|\" @Sp TableAlign") Rules[:_TableAlign2] = rule_info("TableAlign2", "\"|\" @Sp TableAlign")
Rules[:_TableAlign] = rule_info("TableAlign", "< /:?-+:?/ > @Sp { text.start_with?(\":\") ? :left : text.end_with?(\":\") ? :right : nil }") Rules[:_TableAlign] = rule_info("TableAlign", "< /:?-+:?/ > @Sp { text.start_with?(\":\") ? (text.end_with?(\":\") ? :center : :left) : (text.end_with?(\":\") ? :right : nil) }")
Rules[:_DefinitionList] = rule_info("DefinitionList", "&{ definition_lists? } DefinitionListItem+:list { RDoc::Markup::List.new :NOTE, *list.flatten }") 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[:_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 }") Rules[:_DefinitionListLabel] = rule_info("DefinitionListLabel", "StrChunk:label @Sp @Newline { label }")

View file

@ -1065,14 +1065,14 @@ and an extra note.[^2]
def test_gfm_table_2 def test_gfm_table_2
doc = parse <<~'MD' doc = parse <<~'MD'
| Cmd | Returns | Meaning | Cmd | Returns | Meaning
----- | ------- | ------- ----- | :-----: | -------
|"b" | boolean | True if file1 is a block device |"b" | boolean | True if file1 is a block device
"c" | boolean | True if file1 is a character device "c" | boolean | True if file1 is a character device
|"\|" | boolean | escaped bar \| test |"\|" | boolean | escaped bar \| test
MD MD
head = %w[Cmd Returns Meaning] head = %w[Cmd Returns Meaning]
align = [nil, nil, nil] align = [nil, :center, nil]
body = [ body = [
['"b"', 'boolean', 'True if file1 is a block device'], ['"b"', 'boolean', 'True if file1 is a block device'],
['"c"', 'boolean', 'True if file1 is a character device'], ['"c"', 'boolean', 'True if file1 is a character device'],