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

Built-in style for RST (reStructuredText Markup) table #61

Open
pkbehera opened this issue Feb 24, 2021 · 4 comments
Open

Built-in style for RST (reStructuredText Markup) table #61

pkbehera opened this issue Feb 24, 2021 · 4 comments
Labels
enhancement New feature or request

Comments

@pkbehera
Copy link

+------------------------+------------+----------+----------+
| Header row, column 1   | Header 2   | Header 3 | Header 4 |
| (header rows optional) |            |          |          |
+========================+============+==========+==========+
| body row 1, column 1   | column 2   | column 3 | column 4 |
+------------------------+------------+----------+----------+
| body row 2             | ...        | ...      |          |
+------------------------+------------+----------+----------+

an RST table looks like this, see https://docutils.sourceforge.io/docs/ref/rst/restructuredtext.html#grid-tables

Do we have a build-in table style in libfort that gives result like above? If not can we add one (please name it RST_STYLE)

@seleznevae seleznevae added the enhancement New feature or request label Feb 25, 2021
@seleznevae
Copy link
Owner

seleznevae commented Feb 25, 2021

Hi!
At the moment it is not possible. I tried to add a new style but it produces a correct ReST only for a one row header like:

+------+--------------------------+------+--------+
| Rank | Title                    | Year | Rating |
+======+==========================+======+========+
|  1   | The Shawshank Redemption | 1994 |    9.5 |
+------+--------------------------+------+--------+
|  2   | 12 Angry Men             | 1957 |    8.8 |
+------+--------------------------+------+--------+

For headers with multiple rows it shows incorrect result:

+------+--------------------------+------+--------+
| Rank | Title                    | Year | Rating |
+======+==========================+======+========+
| Rank | Title                           | Rating |
+======+==========================+======+========+
| Rank | Title                    | Year | Rating |
+======+==========================+======+========+
|  1   | The Shawshank Redemption |          1994 |
+------+--------------------------+------+--------+
|  2   | 12 Angry Men                    |    8.8 |
+------+--------------------------+------+--------+

I believe that to implement it properly it is needed to refactor how styles are defined and maybe add an additional symbol to styles. It will take some time to implement it properly.

Maybe I'll add the current version that works ok for one row header and later take some time to improve it in another ticket. Not sure yet.

@pkbehera
Copy link
Author

pkbehera commented Feb 25, 2021

static constexpr struct ft_border_style RST_STYLE {
  {
      "-",  // top_border_ch
      "-",  // separator_ch
      "-",  // bottom_border_ch
      "|",  // side_border_ch
      "+",  // out_intersect_ch
      "+",  // in_intersect_ch
  },        // border_chs
      {
          "-",  // top_border_ch
          "=",  // separator_ch (for Sphinx to know that it's the table header)
          "-",  // bottom_border_ch
          "|",  // side_border_ch
          "+",  // out_intersect_ch
          "+",  // in_intersect_ch
      },        // header_border_chs
      "-"       // hor_separator_char
};

fort::table table;
table.set_border_style(&RST_STYLE);

My table header has only one row and the above did work for me. Can this be any better/shorter?

@seleznevae
Copy link
Owner

I did pretty much the same. It should be ok for a one-row header. Without an appropriate built-in style I think it is the simplest way to get what you want at the moment.

@pkbehera
Copy link
Author

can you add a built-in style that works for one-row headers? We can extend that later for multi-row headers

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

No branches or pull requests

2 participants