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

New pipe table line width calculations yield some unnatural column widths #7847

Closed
jjallaire opened this issue Jan 18, 2022 · 7 comments
Closed
Labels

Comments

@jjallaire
Copy link

The change in pipe table line width detection calculation (79e6f8d) can lead to some sub-optional HTML output, especially when there are hyperlinks in one of the columns. For example, consider this markdown:

| JATS Element                                                                                    | Description                      |
|-------------------------------------------------------------------------------------------------|----------------------------------|
| [`<given-names>`](https://jats.nlm.nih.gov/publishing/tag-library/1.2/element/given-names.html) | All given names of a person.     |
| [`<contrib>`](https://jats.nlm.nih.gov/publishing/tag-library/1.2/element/contrib.html)         | Information about a contributor. |

When rendered to HTML the following <colgroup> tag is emitted:

<colgroup>
   <col style="width: 74%" />
   <col style="width: 25%" />
</colgroup>

Which results in the following display:

Screen Shot 2022-01-18 at 12 16 09 PM

As the page gets narrower the problem exacerbates:

Screen Shot 2022-01-18 at 12 18 13 PM

@jjallaire jjallaire added the bug label Jan 18, 2022
@jgm
Copy link
Owner

jgm commented Jan 18, 2022

What authors who use pipe tables have to recognize is that, if their table extends beyond the column set by --columns (default 72 I think), then they are in charge of determining the relative widths by adjusting the widths of the --- separators. This is much more predictable than before the change, since before the change you couldn't tell from the source whether the table was going to get explicit column widths based on the separators. So, I still think it's a worthwhile change. And the solution is quite easy:

| JATS Element                                                                                    | Description                      |
|--------------------------|-----------------------------------------------------------------|
| [`<given-names>`](https://jats.nlm.nih.gov/publishing/tag-library/1.2/element/given-names.html) | All given names of a person.     |
| [`<contrib>`](https://jats.nlm.nih.gov/publishing/tag-library/1.2/element/contrib.html)         | Information about a contributor. |

@jjallaire
Copy link
Author

Okay, the new behavior does seem better specified and less surprising.

My particular concern here is partly driven by the fact that we have a visual editor for Pandoc markdown that edits the JSON representation of the AST and then uses Pandoc to serialize it to and from markdown. So for this scenario the user can't manually tweak the markdown --- separators. They can however size the columns in the visual editor however the pipe table writer doesn't seem to respect the AST column widths (i.e. it doesn't emit markdown like your example above).

Consider my original table example (table.md) rendered w/ pipe_tables and the following Lua filter colwidths.lua that forces the column widths to 0.3 and 0.7:

function Table(tbl)
  tbl = pandoc.utils.to_simple_table(tbl)
  tbl.widths = { 0.3, 0.7 }
  return pandoc.utils.from_simple_table(tbl)
end
$ quarto table.md --lua-filter colwidths.lua --to markdown_strict+pipe_tables
| JATS Element                                                                                    | Description                      |
|-------------------------------------------------------------------------------------------------|----------------------------------|
| [`<given-names>`](https://jats.nlm.nih.gov/publishing/tag-library/1.2/element/given-names.html) | All given names of a person.     |
| [`<contrib>`](https://jats.nlm.nih.gov/publishing/tag-library/1.2/element/contrib.html)         | Information about a contributor. |

It would be great if the 0.3 and 0.7 column widths were reflected in the widths of the --- separators.

Note that if I do the same render to grid_tables the text representation does indeed reflect the column widths:

 $ pandoc table.md --lua-filter colwidths.lua --to markdown_strict+grid_tables
+--------------------+-------------------------------------------------+
| JATS Element       | Description                                     |
+====================+=================================================+
| [`<gi              | All given names of a person.                    |
| ven-names>`](https |                                                 |
| ://jats.nlm.nih.go |                                                 |
| v/publishing/tag-l |                                                 |
| ibrary/1.2/element |                                                 |
| /given-names.html) |                                                 |
+--------------------+-------------------------------------------------+
| [`<contrib>`](h    | Information about a contributor.                |
| ttps://jats.nlm.ni |                                                 |
| h.gov/publishing/t |                                                 |
| ag-library/1.2/ele |                                                 |
| ment/contrib.html) |                                                 |
+--------------------+-------------------------------------------------+

@jgm
Copy link
Owner

jgm commented Jan 18, 2022

Simple tables by definition don't have (nonzero) column widths, so that may be the issue if you're using from_simple_table?
I'd have to check on how that works.

@jgm
Copy link
Owner

jgm commented Jan 18, 2022

You're right, the markdown writer doesn't take account of widths in writing pipe tables. If that changed, would that fix things for you?

@jjallaire
Copy link
Author

Yes, if the pipe table writer reflected the column widths in the AST that would indeed fix things!

@jgm jgm closed this as completed in 6723891 Jan 19, 2022
@jgm
Copy link
Owner

jgm commented Jan 19, 2022

OK, I think this might be fixed by the commit I just pushed.
But it's somewhat fiddly getting the widths calculated by the reader and writer to match up (esp. with rounding from non-integers). Real-world testing will be helpful, but I think this should at least be an improvement.

@jjallaire
Copy link
Author

Okay, that's excellent! Thank you :-)

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

No branches or pull requests

2 participants