QuantEcon / sphinxcontrib-jupyter

A Sphinx Extension for Generating Jupyter Notebooks
BSD 3-Clause "New" or "Revised" License
76 stars 23 forks source link

TEST: add test for tables types including basic RST and table directives #43

Closed mmcky closed 6 years ago

mmcky commented 6 years ago

This is an expanded set of test tables from rst2ipynb. It includes various table syntax simple tables, grid tables and tables build by csv-table and list-table directives.

Status: Currently fails for the simplest grid table case from the docutils specification of RST

A simple table:

+------+------+
| C1   | C2   |
+------+------+
| a    | b    |
+------+------+
| c    | d    |
+------+------+

get's migrated as:

image

which looks like

image

mmcky commented 6 years ago

Doing a bit of research suggests that many markdown parsers do not support tables without a header. This is the main reason the first table fails in this set of tests.

https://stackoverflow.com/questions/17536216/create-table-without-header-in-markdown

If Jupyter is using Github Flavoured Markdown then this might not be a valid test.

The alternative would be to add a blank header to trigger the parser to render the table

| | |
|-------|-------|
| C1   | C2   |
| a    | b    |
| c    | d    |

which would render like this in the notebook with a single solid black line:

image

It is convenient to conform to the markdown as closely as possible in my view as the generated output is more easily editable within the notebook.

Another option would be to switch to using html tables which seems to be the rst2ipynb approach

<table style="width:19%;">
<colgroup>
<col width="9%" />
<col width="9%" />
</colgroup>
<tbody>
<tr class="odd">
<td>C1</td>
<td>C2</td>
</tr>
<tr class="even">
<td>a</td>
<td>b</td>
</tr>
<tr class="odd">
<td>c</td>
<td>d</td>
</tr>
</tbody>
</table>

would render

C1 C2
a b
c d
mmcky commented 6 years ago

I think html based tables would make editing very difficult. Perhaps the best solution is not to support tables without headers.

mmcky commented 6 years ago

Taken a survey and given this extension is about generating notebooks -- the opinion seems to be the best strategy is to support the RST specification as fully as we can. Therefore we should probably allow for both html and markdown generated tables as an option in the config file. If a user chooses markdown table output then for cases that aren't supported in markdown we would insert an html table. html generated tables should be the default output option for all tables to ensure they are rendered in the same style.

mmcky commented 6 years ago

I will merge this as is. The extension currently supports construction of relatively simple markdown tables. html support will be tracked by issue #53 and #54