WeBWorK Main Forum

HTML table borders

HTML table borders

by Paul Pearson -
Number of replies: 7

We recently upgraded our server to ww_version 2.17 from 2.12 and have noticed that HTML tables are rendered without vertical and horizontal bars to separate the cells (see example image below).  Can this be fixed for all problems that have HTML tables using CSS, and, if so, what file(s) need to be edited and what should the edits be?  (Question of lesser import: Is anyone else experiencing this, or is it just our local configuration?)  Thanks in advance!

 

Image of Library/Michigan/Chap2Sec1/Q17.pg with an html table that does not have borders on its interior cells.


In reply to Paul Pearson

Re: HTML table borders

by Arnold Pizer -

Answering your less important question, I see the same thing on a fresh install.

In reply to Arnold Pizer

Re: HTML table borders

by Glenn Rice -

This seems to vary with the browser.  In Firefox I see the table lines, but I do not in Google Chrome.

I believe this may be a larger PG issue that we are going to need to sort out.  PG uses lots of deprecated table attributes for styling.  In this case PG uses the "border" attribute.  That is deprecated, and it is only a matter of time until all browsers stop honoring that attribute.  It may be that Google Chrome has already done so, and that Firefox still is honoring it for now.  PG needs to be updated to stop using those things, and to instead use css which is the new (by new I mean new for 10 years or so) way of doing this.

In reply to Glenn Rice

Re: HTML table borders

by Paul Pearson -
Indeed, I am using the Google Chrome browser. My temporary workaround is to add some CSS style attributes to my PGcourse.pl file (see code below). For some reason, the border attributes aren't putting in cell borders (so maybe I should remove those lines of code), but the extra padding in my CSS does work and makes the tables readable.

I'm pretty sure all of my the webwork problems are set up to read PGcourse.pl so this should work for me right now (or, is it now the default that every webwork problem reads PGcourse.pl regardless of whether it's explicitly loaded by the problem's PG file?).

Long term, it seems to me it would be best to rewrite all of the table macros (in PGbasicmacros.pl and the table specific macros like unionTables.pl and the niceTables.pl and any others) so that they create a div or span wrapper around tables with a css style that only applies to those divs or spans.

# [templates]/macros/PGcourse.pl file contents

sub _PGcourse_init {}; # Don't reload this file.

main::POST_HEADER_TEXT(main::MODES(TeX=>"", HTML=><<'END_SCRIPTS'));
    <style>
    table, th, td {
      border: 1px solid;
      border-collapse: collapse;
      padding: 4px 6px 4px 6px; /* top, right, bottom, left */
    }    
    </style>
END_SCRIPTS

1;

Attachment Screenshot from 2022-09-02 14-41-19.png
In reply to Paul Pearson

Re: HTML table borders

by Glenn Rice -

So it seems that the issue is not that Chrome does not honor the border attribute.  Doing some testing I see that it still does.  However, bootstrap sets the border for all tables to "0 solid" and the css overrides that attribute.  Apparently I knew about this and I added the "border: revert" css to the style in problem.css to counteract that.  Firefox honors that, but it seems that Chrome does not.

Soon the code in PG needs to be modified to output tables with the appropriate css class with css style in problem.css (really problem.scss).  It is not necessary to wrap tables in a div.  You can put the class directly on the table.  Although that depends on what is needed.  For borders the table can directly have the style.  For responsive tables a containing div will be needed.

In reply to Glenn Rice

Re: HTML table borders

by Paul Pearson -

Thanks, Glenn.  In the meantime, is there something that could be changed course-wide or site-wide to get internal borders back?  Just curious.  The extra spacing certainly works but is not what I consider ideal.  Thanks in advance!

In reply to Paul Pearson

Re: HTML table borders

by Alex Jordan -

That particular problem file loads PGcourse.pl, so there is a non-invasive way to work around the issue. In your PGcourse.pl file (in the templates/macros/ folder; create one if there isn't one yet) you could redefine the macro(s) from PGbasicmacros that are at fault here. You could try redefining sub begintable (https://github.com/openwebwork/pg/blob/main/macros/PGbasicmacros.pl#L2737) so that where it currently uses BORDER='1', it would instead have

style="border: 1px solid black;"

or something like that.

This would not affect any repository files so it would not complicate things with your next upgrade. But also it would only help for exercises that load PGcourse.pl, and load it after PGbasicmacros.pl. And this is nothing to worry about but your apache error log would probably start accruing entries about this subroutine being redefined.


In reply to Alex Jordan

Re: HTML table borders

by Glenn Rice -

You could also make the changes in my pull request https://github.com/openwebwork/pg/pull/723 that addresses this issue.  Although that would be a bit more invasive, and would complicate your next upgrade slightly.