asciidoctor / asciidoctor-intellij-plugin

AsciiDoc plugin for products on the IntelliJ platform (IDEA, RubyMine, etc)
https://intellij-asciidoc-plugin.ahus1.de/
Apache License 2.0
356 stars 146 forks source link

AsciiDoc table prettifier #1396

Open Andronovss opened 1 year ago

Andronovss commented 1 year ago

Why the new feature should be added

Very often, tables in adoc don't look too good for visual presentation, especially after converting from other formats. Also, we need to format tables in a more readable way for humans. Now, we have to align the table elements manually. It would be great to have the same functionality to control tables visually as the MarkdownTablePrettify-VSCodeExt plugin has.

How the new feature should work

We have two tables as examples in this case:

.beforeFormate
|===
|Header 1 |Header 2 |Header 3

|Column 1, row 1 |Column 2, row 1     |Column 3, row 1

|Column 1, row 2   |Column 2, row 2 |Column 3, row 2

   |Column 1, row 3  |Column 2, row 3     |Column 3, row 3
|===

and

.afterFormate
|===
|Header 1        |Header 2        |Header 3

|Column 1, row 1 |Column 2, row 1 |Column 3, row 1

|Column 1, row 2 |Column 2, row 2 |Column 3, row 2

|Column 1, row 3 |Column 2, row 3 |Column 3, row 3
|===

I saw the post https://github.com/asciidoctor/atom-language-asciidoc/issues/140 and even agree in some ways. After two days of researching, I could not find an acceptable algorithm for bypassing tables precisely because of the table customization options in adoc.

Perhaps, we should restrict the usage of the table formatting and limit ourselves to the simple option.

mojavelinux commented 1 year ago

The practice of putting multiple table cells on the same line is considered an anti-pattern in the AsciiDoc ecosystem, largely for this reason. AsciiDoc allows each cell to be placed on its own line, similar to the style of a list. I would dislike seeing an IDE encouraging the use of spaces to align columns in the table source. It makes the document harder to edit and encourages the busy work of aligning cells in a column. I would much prefer the IDE rearrange cells horizontally, with an empty line to separate rows.

See https://docs.asciidoctor.org/asciidoc/latest/tables/add-cells-and-rows/#consecutive and

Andronovss commented 1 year ago

Dan, I totally agree with you on all points.

My version of the new feature is rather a very rare case when we get an adoc file from another format such as docx. That's when we have to do table formatting for better human readability.

Andronovss commented 1 year ago

Wrote a script in python that formats the simplest of tables.

https://github.com/Andronovss/asciidocTablePrettify/tree/master