Skip to content

Commit

Permalink
PGML tables
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex-Jordan committed Oct 10, 2023
1 parent f1232bc commit 3eb23ff
Showing 1 changed file with 19 additions and 10 deletions.
29 changes: 19 additions & 10 deletions macros/core/PGML.pl
Original file line number Diff line number Diff line change
Expand Up @@ -596,7 +596,10 @@ sub NOOP {
ignoreIndent => 1,
terminator => qr/#\]/,
allowStar => 1,
options => [ "align", "midrules", "center" ]
options => [ qw(
center caption horizontalrules texalignment align Xratio encase rowheaders headerrules
valign padding tablecss captioncss columnscss datacss headercss allcellcss booktabs
) ]
},
"[-" => {
type => 'table-row',
Expand All @@ -611,8 +614,11 @@ sub NOOP {
parseAll => 1,
isContainer => 1,
container => 'table-row',
terminator => qr/.\]/,
options => ["headerrow"]
terminator => qr/\.\]/,
options => [ qw(
halign header color bgcolor b i m noencase colspan top bottom
cellcss texpre texpost texencase rowcolor rowcss headerrow rowtop rowbottom valign
) ]
},
"[:" => {
type => 'math',
Expand Down Expand Up @@ -1273,7 +1279,6 @@ sub string {
foreach my $item (@{ $block->{stack} }) {
$self->{item} = $item;
$self->{nl} = (!defined($strings[-1]) || $strings[-1] =~ m/\n$/ ? "" : "\n");
# warn "type: $item->{type}";
for ($item->{type}) {
/indent/ && do { $string = $self->Indent($item); last };
/align/ && do { $string = $self->Align($item); last };
Expand All @@ -1300,7 +1305,7 @@ sub string {
/table/ && do { $string = $self->Table($item); last };
PGML::Warning "Warning: unknown block type '$item->{type}' in " . ref($self) . "::format\n";
}
push(@strings, $string) unless $string eq '';
push(@strings, $string) unless (!defined $string || $string eq '');
}
$self->{nl} = (!defined($strings[-1]) || $strings[-1] =~ m/\n$/ ? "" : "\n");
return join('', @strings);
Expand Down Expand Up @@ -1336,14 +1341,18 @@ sub Table {
my $self = shift;
my $item = shift;
return "[misplaced $item->{type}]" if $item->{hasWarning};
my $def = [ $item->{type} eq 'table-cell' ? $self->string($item) : map { $self->Table($_) } @{ $item->{stack} } ];
my @options = ();
my @options;
foreach my $option (@{ $item->{options} || [] }) {
push(@options, $option => $item->{$option}) if defined($item->{$option});
}
push(@$def, @options) if @options;
return $def unless $item->{type} eq 'table';
return ($item->{hasStar} ? main::LayoutTable($def) : main::DataTable($def));
if ($item->{type} eq 'table-cell') {
return [ $self->string($item), @options ];
} elsif ($item->{type} eq 'table-row') {
return [ map { $self->Table($_) } @{ $item->{stack} } ];
} elsif ($item->{type} eq 'table') {
my $def = [ map { $self->Table($_) } @{ $item->{stack} } ];
return ($item->{hasStar} ? main::LayoutTable($def, @options) : main::DataTable($def, @options));
}
}

sub Math {
Expand Down

0 comments on commit 3eb23ff

Please sign in to comment.