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

niceTables.pl layout table not terminated properly with mismatched cell count #1182

Open
drgrice1 opened this issue Jan 21, 2025 · 1 comment

Comments

@drgrice1
Copy link
Member

Here is a MWE that shows the problem:

DOCUMENT();
loadMacros(qw{PGstandard.pl PGML.pl});

BEGIN_PGML
[#
    [.A.] [.B.] [.C.]*
    [.D.] [.E.]
#]*{ align => 'ccc' }

Content after
END_PGML

ENDDOCUMENT();

In that example, the "Content after" is not after the table. Instead it appears to be in a third row of the table. Really it is just inside the div that is supposed to contain the table. The following is the generated html for the problem:

<div class="PGML">
    <div style="margin: auto; display: table; border-collapse: collapse">
        <div style="display: table-row">
            <div style="vertical-align: top; padding: 0.85rem 0.85rem; text-align: center; display: table-cell">A</div>
            <div style="vertical-align: top; padding: 0.85rem 0.85rem; text-align: center; display: table-cell">B</div>
            <div style="vertical-align: top; padding: 0.85rem 0.85rem; text-align: center; display: table-cell">C</div>
        </div>
        <div style="display: table-row">
            <div style="vertical-align: top; padding: 0.85rem 0.85rem; text-align: center; display: table-cell">D</div>
            <div style="vertical-align: top; padding: 0.85rem 0.85rem; text-align: center; display: table-cell">E</div>
            <div style="vertical-align: top; padding: 0.85rem 0.85rem; text-align: center; display: table-cell"></div>
        </div>
        <div style="margin-top: 1em"></div>
        Content after
    </div>
</div>
@dpvc
Copy link
Member

dpvc commented Jan 21, 2025

The problem is with this function in niceTables.pl:

pg/macros/ui/niceTables.pl

Lines 1512 to 1528 in afae348

sub tag {
my ($inner, $name, $attributes, $separator) = @_;
$separator = "\n" unless defined $separator;
my $return = "<$name";
for my $x (main::lex_sort(keys %$attributes)) {
$return .= qq( $x="$attributes->{$x}") if ($attributes->{$x} ne '');
}
if ($inner ne '') {
$return .= ">$separator";
$return .= $inner;
$return .= "$separator</$name>";
} else {
$return .= '>' unless ($main::displayMode eq 'PTX');
$return .= '/>' if ($main::displayMode eq 'PTX');
}
return $return;
}

In order to pad a short line (when align is set), niceTables tries to insert empty cells, but the empty content prevents tag() from adding the close tag. That means the resulting table is improperly nested. You are seeing that here.

One possible solution is to change

data => '',

so that the data is ' ' with a space instead of empty. That way, tag() will properly close the <div> used for the table.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants