asciidoctor / asciidoctorj

:coffee: Java bindings for Asciidoctor. Asciidoctor on the JVM!
http://asciidoctor.org
Apache License 2.0
617 stars 172 forks source link

Fixes #1265. Support setting column widths #1270

Closed robertpanzer closed 3 months ago

robertpanzer commented 3 months ago

Thank you for opening a pull request and contributing to AsciidoctorJ!

Please take a bit of time giving some details about your pull request:

Kind of change

Description

What is the goal of this pull request?

Add support for setting the width of table columns. While columns have a method setWidth() that sets the attribute width of a column, this does not become effective. In addition it is required to set the attribute colpcwidth, which Asciidoctor core only sets internally when calling Table#assign_column_widths.

How does it achieve that?

This PR adds a method Table.assignColumnWidths which calls the Ruby method mentioned above.

Are there any alternative ways to implement this?

Very likely.

Are there any implications of this pull request? Anything a user must know?

There should be no change of existing behavior.

Issue

If this PR fixes an open issue, please add a line of the form:

Fixes #1265

This PR is a draft until more tests, in particular for the auto width_cols are added.

Release notes

Please add a corresponding entry to the file CHANGELOG.adoc

robertpanzer commented 3 months ago

I added a test that uses autowidth columns, where the width attribute has a negative value. Together with that I was considering adding an overloaded implementation for assignColumnWidths that allows to pass the widthBase. Testing this I realized that I do not understand properly how this works, since the assigned widths were just the absolute widths set on the columns. I.e., if I set the widths to 2, 3 and -1 for 3 columns, even with a width base of 10 the widths in the resulting html were 2, 3 and not set. Therefore, I kept it like it is now, with only one implementation for assignColumnWidths.

robertpanzer commented 3 months ago

I can backport this to 2.5.x.