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

Option to use list-tables in rST writer. #4564

Closed
NickVolynkin opened this issue Apr 19, 2018 · 27 comments
Closed

Option to use list-tables in rST writer. #4564

NickVolynkin opened this issue Apr 19, 2018 · 27 comments

Comments

@NickVolynkin
Copy link

It would be great if pandoc could write list-tables instead of the usual grid-like tables.

The grid-like rST tables have several faults that list-tables do not have:

  • Hard to add formatted content, such as code blocks.
  • Hard to edit, as you have to keep all the 'border' characters on their places.
  • Hard to swap content between cells in a row. Well, unless you have mastered an editor with block operations.

I've searched through pandoc -h, tests and source code but could not find anything related. If there's a filter that can do it, please drop a link. 😄

@qingpeng
Copy link

This will be very helpful!

@danse
Copy link
Contributor

danse commented May 10, 2018

how do you imagine the user interface for this? an extension for the writer?

@NickVolynkin
Copy link
Author

NickVolynkin commented May 11, 2018

@danse maybe as a command line option for the writer:

pandoc -f html -t rst --list-tables test.html -o result.rst

Although, in my opinion the list-table syntax is so much better than the grid-table, that is should be the default option. I've added a bug report that can be solved by switching to list-tables.

@jgm
Copy link
Owner

jgm commented May 11, 2018 via email

@NickVolynkin
Copy link
Author

@jgm in my company it's a question of documentation style guide. We have to choose one syntax option and stick to it. We chose list-tables for many reasons.

Same with headers: rST allows using any character for any header level, but when you see a header, you should know the level without reading the whole document. So we chose =-~^, just like in Pandoc.

Indeed, people may want to use both styles. Maybe the answer is to use grid-tables in simple cases and switch to list-tables if table contains lists, code blocks, URL's, long words or any other complex things. Then a global option could be used to enforce always using one of the syntaxes. I can help with gathering a set of examples of such things.

Another option could be to mark tables with special classes in native representation. Then someone using Pandoc to write rST would implement their own logic to make a decision about each table, then add a marker class and pass the sources to Pandoc.

@danse
Copy link
Contributor

danse commented May 11, 2018 via email

@NickVolynkin
Copy link
Author

honestly i am curious about the motivations you mention in favour of list-tables.

@danse First, some insight into how I'm using Pandoc. We have lots of documentation in a legacy authoring system. Tens of guides, many languages. All these docs will be converted from HTML to rST/Sphinx projects. New sources should be consisent in style and syntax, because we will update and improve them a lot. So we've defined a single true way for doing anything that has more than one option. For tables we chose the list-table syntax. Here's why:

  • List-tables have familiar syntax. A list-table is almost the same as a nested list in rST or Markdown, but with a .. list-table:: directive added. Having experience with YAML also helps work with list-tables.
  • List-tables have the stub-columns and header-rows parameters that grid-tables don't. Sometimes we have tables with several header rows.
  • It's much easier to edit list-tables. Adding, moving and deleting rows and cells is basically just copying and pasting blocks of lines. To add formatted content from elsewhere you just paste and indent it.
  • In grid-tables, on the contrary, you have to block-select text all the time. Any time you add a single character, you have to remove one or several spaces to keep table "walls" in place. That's a lot of extra meaningless work to do.
  • On the other hand, small grid-tables with plain text are easier to read in source code. Maybe they are better in code comments that go to autogenerated docs.
  • Also, there are csv-tables. Can't contain any complex formatting, but perfect for showing program-generated content. If I'll ever have to show test results or performance metrics in Sphinx, I'll use csv-tables.

@danse
Copy link
Contributor

danse commented May 24, 2018

Thanks, that seems to be plenty of reasons. The rST documentation about list tables is very concise so it's not clear to me how to structure a list table containing nested markup like in the case of code with long lines. Does anybody have an example of a complex list table? It would help to assess how this option would affect the users

@NickVolynkin
Copy link
Author

@danse here's an example of a list-table with paragraphs, block and inline code from our docs.

danse added a commit to italia/pandoc that referenced this issue Jun 13, 2018
@danse
Copy link
Contributor

danse commented Jun 24, 2018

This test derived from your complex table example succeeds with the code in that branch. While i'm working on improvements i could use some directions from the future users of this feature.

Indentation levels are chosen in order to follow those currently used for bullet lists, in order to reuse the code. Do we have any good reason to do differently?

It is not clear to me how to precisely find the options supported by a directive. Looking at the docutils code it seems like the supported options are name, class, widths, stub-columns and header-rows. Here is the doc about class and name.

I assume that widths are the desired widths ... with sizes expressed in proportions of the column width of the document? I assume that header-rows is just an integer specifying how many of the rows are headers, and in the case of pandoc documents i think that this number can either be 0 or 1. I am not sure about stub-columns.

Any pointer to better doc is appreciated, if i won't find anything better i could look at the docutils code. Currently i think that i will produce header-rows (0 or 1) and widths when the case. Please let me know in case i forgot anything that could be important

@danse
Copy link
Contributor

danse commented Jul 16, 2018

This might be too technical for some readers but it makes sense to write it here: in the RST writer i see that class and name are written for elements that have Attr in their native representation. Table does not have Attr so i would not add class and name

danse added a commit to italia/pandoc that referenced this issue Jul 18, 2018
danse added a commit to italia/pandoc that referenced this issue Jul 18, 2018
@danse
Copy link
Contributor

danse commented Jul 18, 2018

alright, pull request #4780 is finally adding this feature 🙂

danse added a commit to italia/pandoc that referenced this issue Jul 19, 2018
this changes the API adding a global `--list-table` option which only
affects the rST writer, and causes all tables to be rendered using the
list table syntax documented here
http://docutils.sourceforge.net/docs/ref/rst/directives.html#list-table
danse added a commit to italia/pandoc that referenced this issue Sep 8, 2018
this changes the API adding a global `--list-table` option which only
affects the rST writer, and causes all tables to be rendered using the
list table syntax documented here
http://docutils.sourceforge.net/docs/ref/rst/directives.html#list-table
@petterreinholdtsen
Copy link

Hi. I have a national standard document I would like to convert to RST with list-table. Is there any hope to have an official pandoc version with this support? I tried unsuccessfully to build the code from the above mentioned pull request, without success (some version skew, not sure what was wrong), and thus hope an official pandoc version will be released with thus support, so I can pick it up via Debian. :)

@jgm
Copy link
Owner

jgm commented Mar 24, 2020

The main thing blocking this is figuring out a good way to trigger the table style. I'd prefer not to have a command-line option that just affects rst rendering, and affects it globally. Better to be able to mark up tables individually. However, currently, there's no way to put attributes on tables. This should change soon, hopefully, and then we'll have a way to

mark tables with special classes in native representation

@petterreinholdtsen
Copy link

petterreinholdtsen commented Mar 24, 2020 via email

@tpatnoe
Copy link

tpatnoe commented May 13, 2020

I too would love to see this feature. The only solution I have now is to also install rstdoc with pip install rstdoc and use the rstlisttable after converting to RST with pandoc.

@jgm jgm added this to the next release milestone May 21, 2020
@danse
Copy link
Contributor

danse commented Jan 29, 2021

I haven't been working on pandoc in years and i'm definitely out of training, anyway this is a relatively simple update of an existing patch so here is the new pull request

danse added a commit to danse/pandoc that referenced this issue Jan 29, 2021
this changes the API adding a global `--list-table` option which only
affects the rST writer, and causes all tables to be rendered using the
list table syntax documented here
http://docutils.sourceforge.net/docs/ref/rst/directives.html#list-table
@BaardBouvet
Copy link

BaardBouvet commented May 18, 2021

I tried the patch, and from what I can tell it produced RST that Pandoc is not able to read back in:

$ cat test.rst 
.. list-table::
  :widths: 50 50
  :header-rows: 1

  * - Left
    - Right
  * - Second
    - row
$ pandoc test.rst --list-table -t rst | ~/.local/bin/pandoc -f rst -t native
[Table ("",[],[]) (Caption Nothing
 [])
 []
 (TableHead ("",[],[])
 [])
 [(TableBody ("",[],[]) (RowHeadColumns 0)
  []
  [Row ("",[],[])
   []])]
 (TableFoot ("",[],[])
 [])]

The format that is output-ed by this patch is:

.. list-table::
   :widths: 36 36
   :header-rows: 1

   - 

      - Left
      - Right
   - 

      - Second
      - row

@petterreinholdtsen
Copy link

petterreinholdtsen commented May 18, 2021 via email

@jgm
Copy link
Owner

jgm commented May 18, 2021

We could easily change the patch to produce the more compact list output (which seems desirable to me).

@BaardBouvet
Copy link

BaardBouvet commented May 20, 2021

[Baard H. Rehn Johansen]
I tried the patch, and from what I can tell it produced RST that Pandoc is not able to read back in:
As far as I can tell, not being an RST expert, the input and output seem to be equivalent. At least any :widths with two identical numbers would work the same way, so "1 1", "50 50" and "36 36" are all the same. And the list in list seem to be equivalent too. What specific do you see that is not understood correctly?

-- Happy hacking Petter Reinholdtsen

The native output after parsing doesn't contain any of the text in the input, it's just a blank table. So the format output-ed by the patch is not parsed correctly by pandoc. I'm not an RST guru, so not sure if the output of the patch is wrong or if the RST reader in pandoc is broken (I suspect the latter).

@jgm
Copy link
Owner

jgm commented May 20, 2021

If this reveals a problem with pandoc's RST list parsing, then you might open a new issue for that, using as simple an example as possible (regular list, not list table).

@brogersadobe
Copy link

Just to add support to this need: Here at Adobe our rst/sphinx docs use list tables 100% of the time. Pandoc's grid table output is very time consuming to work with. Keep up the good work.

@danse
Copy link
Contributor

danse commented Sep 18, 2022

hopefully i will get some time to work on this in the next weeks, but i am still blocked by this #4564 (comment) about the feature's design.

personally if i had to convert many documents, the idea of marking every table would sound tedious to me, but i am willing to follow users' consensus and look for another way, since i agree that having a global option is not ideal either. Is it now possible to add attributes to tables, or should this still wait a bit?

@jgm
Copy link
Owner

jgm commented Sep 18, 2022

Yes, Tables can have attributes added to them now -- in the AST. But many input formats (including Markdown) still don't have a way to add attributes directly to a table.

@jgm
Copy link
Owner

jgm commented Sep 18, 2022

It would be good to know, from those who use list tables, whether they have a need to have documents containing some list and some non-list tables.

danse added a commit to danse/pandoc that referenced this issue Sep 24, 2022
When a table is marked with a "list-table" attribute class, it will
now be rendered using the list table syntax documented here
http://docutils.sourceforge.net/docs/ref/rst/directives.html#list-table
@danse
Copy link
Contributor

danse commented Sep 24, 2022

I created a new pull request including the required changes. As discussed, a filter will be required in order to render all tables in a document as list tables.

A filter instance is attached here, along with a test.native file you can use to test the filter, just rename the files removing the final .txt extensions that are needed to upload on github. Once you have made the filter executable as described in the docs, you will be able to run pandoc with the filter and get the following output:

$ pandoc test.native -t rst --filter list-tables.hs
   .. list-table::
      :widths: 11 10 12 27
      :header-rows: 1

      - 

         - Centered Header
         - Left Aligned
         - Right Aligned
         - Default aligned
      - 

         - First
         - row
         - 12.0
         - Example of a row that spans multiple lines.
      - 

         - Second
         - row
         - 5.0
         - Here’s another one. Note the blank line between rows.

list-tables.hs.txt
test.native.txt

@jgm jgm closed this as completed in c974ed0 Sep 29, 2022
jgm added a commit that referenced this issue Sep 29, 2022
[API change] Add writerListTables to WriterOptions.

RST writer: Remove sensitivity to "list-table" class in table attributes.
Instead, just check `writerListTables` in writer options.

See #4564.
jgm added a commit that referenced this issue Sep 27, 2024
- Fix alignment of list items corresponding to cells.
- Don't enclose the list table in a `.. table::`; this leads to
  doubled captions.

Closes #10226.
Closes #10227.
Modified test output for #4564.
jgm added a commit that referenced this issue Sep 27, 2024
- Fix alignment of list items corresponding to cells.
- Don't enclose the list table in a `.. table::`; this leads to
  doubled captions.

Closes #10226.
Closes #10227.
Modified test output for #4564.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

9 participants