Cell version of I checked the specification of cols attribute of AsciiDoc table & internal implementation of Asciidoctor.
Reference site 1 Asciidoctor User Manual #cell seems to have a relatively detailed description.
Specify immediately before the cell (starting with |
). In the example below, the .2 + ^. ^
And 3 + ^
parts.
AsciiDoc
[options="header"]
|===
|Date |Duration | Location | Plan
.2+^.^|2021.01.04 |08:00 | XXX | game
|09:00 | YYY | coding
|2021.01.05 |08:00 | XXX | no plan
|2021.01.06 3+^| work
|===
The output is as follows.
The parse_cellspec
method called from the self.parse_table
method in parser.rb
parser.rb (excerpt & line number supplement)
# Internal: Parse the cell specs for the current cell.
#
# The cell specs dictate the cell's alignments, styles or filters,
# colspan, rowspan and/or repeating content.
#
# The default spec when pos == :end is {} since we already know we're at a
# delimiter. When pos == :start, we *may* be at a delimiter, nil indicates
# we're not.
#
# returns the Hash of attributes that indicate how to layout
# and style this cell in the table.
def self.parse_cellspec(line, pos = :end, delimiter = nil) # 1
m, rest = nil, '' # 2
# 3
if pos == :start # 4
if line.include? delimiter # 5
spec_part, delimiter, rest = line.partition delimiter # 6
if (m = CellSpecStartRx.match spec_part) # 7
return [{}, rest] if m[0].empty? # 8
else # 9
return [nil, line] # 10
end # 11
else # 12
return [nil, line] # 13
end # 14
else # pos == :end # 15
if (m = CellSpecEndRx.match line) # 16
# NOTE return the line stripped of trailing whitespace if no cellspec is found in this case # 17
return [{}, line.rstrip] if m[0].lstrip.empty? # 18
rest = m.pre_match # 19
else # 20
return [{}, line] # 21
end # 22
end # 23
# 24
spec = {} # 25
if m[1] # 26
colspec, rowspec = m[1].split '.' # 27
colspec = colspec.nil_or_empty? ? 1 : colspec.to_i # 28
rowspec = rowspec.nil_or_empty? ? 1 : rowspec.to_i # 29
if m[2] == '+' # 30
spec['colspan'] = colspec unless colspec == 1 # 31
spec['rowspan'] = rowspec unless rowspec == 1 # 32
elsif m[2] == '*' # 33
spec['repeatcol'] = colspec unless colspec == 1 # 34
end # 35
end # 36
# 37
if m[3] # 38
colspec, rowspec = m[3].split '.' # 39
if !colspec.nil_or_empty? && TableCellHorzAlignments.key?(colspec) # 40
spec['halign'] = TableCellHorzAlignments[colspec] # 41
end # 42
if !rowspec.nil_or_empty? && TableCellVertAlignments.key?(rowspec) # 43
spec['valign'] = TableCellVertAlignments[rowspec] # 44
end # 45
end # 46
# 47
if m[4] && TableCellStyles.key?(m[4]) # 48
spec['style'] = TableCellStyles[m[4]] # 49
end # 50
# 51
[spec, rest] # 52
end # 53
Matching processing is performed on the 7th and 16th lines. The regular expressions used are as follows.
rx.rb (excerpt & comment omitted & supplement)
# Examples
# 2.3+<.>m
# m[1] m[2] m[3] m[4]
# <---------------------------><----> <-------------------------------------> <----->
CellSpecStartRx = /^[ \t]*(?:(\d+(?:\.\d*)?|(?:\d*\.)?\d+)([*+]))?([<^>](?:\.[<^>]?)?|(?:[<^>]?\.)?[<^>])?([a-z])?$/
CellSpecEndRx = /[ \t]+(?:(\d+(?:\.\d*)?|(?:\d*\.)?\d+)([*+]))?([<^>](?:\.[<^>]?)?|(?:[<^>]?\.)?[<^>])?([a-z])?$/
CellSpecStartRx
seems to be for the beginning of a line, and CellSpecEndRx
seems to be for other purposes.
--m [1] m [2]: In the case of integer``
. integer` `+` ... The number of columns to join (horizontal direction) and the number of rows to join (vertical direction). <br> `.` and later can be omitted. Alternatively, you can omit the part before `.`. --m [1] m [2]: For `integer
* ... Repeat the same cell for the specified number of columns (see Reference Site 1). --m [3]: Horizontal direction (
< or
^ or
>)
. Vertical direction (
< or
^ or
>) ・ ・ ・ Alignment Horizontal (left justified, center justified, Right-justified) and vertical (top-justified, center-justified, bottom-justified). <br>
.and later can be omitted. Alternatively, you can omit the part before
.. --m [4]:
Character` ・ ・ ・ Format specification
Recommended Posts