Join 34,000+ subscribers and receive articles from our
blog about software quality, testing, QA and security.

Markdown syntax for tables


#1

Hello,

First of all, possibility to add tables in the fields is great !
But now, I am trying to convert these tables into HTML with a Markdown parser, and it does not work.

I am getting raw data with the python API, and trying to use mardown2.markdown to convert it into HTML. (see example on this page, it works well).

Here is a little example with the table which is given in the user guide:

In> table = "||| :Page | :Option      | :Value | :Error Range\r\n\
    ...: || Page 1 | Page Margin  | 2cm    | 0.5cm \r\n\
    ...: || Page 2 | Zoom Percent | 120%   | 0\r\n\
    ...: || Page 3 | Tab Depth    | 5      | 4-6 \r\n\
    ...: || Page 4 | Type Speed   | 20     | 15-25"

In> markdown2.markdown(table, extras=["tables"])
Out> u'<p>||| :Page | :Option      | :Value | :Error Range\n|| Page 1 | Page Margin  | 2cm    | 0.5cm \n|| Page 2 | Zoom Percent | 120%   | 0\n|| Page 3 | Tab Depth    | 5      | 4-6 \n|| Page 4 | Type Speed   | 20     | 15-25</p>\n'

Is it normal ? Is there a workaround ?


#2

Hi Romain,

Thanks for your posting. I believe tables were not part of the original Markdown format but were added later and there may be incompatibilities between the different table implementations and formats. Can you check if your converter expects the same table format? You may need to change TestRail’s format slightly to match the expected format of your converter (e.g. just two pipes instead of three to start a table).

Cheers,
Tobias


#3

I did a few tests and found out that the parser only needs a line full of “—” to detect a table:

In> table = "||| :Page | :Option      | :Value | :Error Range\r\n\
    ...: | --- | --- | --- | ---\r\n\
    ...: || Page 1 | Page Margin  | 2cm    | 0.5cm \r\n\
    ...: || Page 2 | Zoom Percent | 120%   | 0\r\n\
    ...: || Page 3 | Tab Depth    | 5      | 4-6 \r\n\
    ...: || Page 4 | Type Speed   | 20     | 15-25"
In> markdown(table, extras=["tables"])
Out> u'<table>\n<thead>\n<tr>\n  <th></th>\n  <th></th>\n  <th>:Page</th>\n  <th>:Option</th>\n  <th>:Value</th>\n  <th>:Error Range</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n  <td></td>\n  <td>Page 1</td>\n  <td>Page Margin</td>\n  <td>2cm</td>\n  <td>0.5cm</td>\n</tr>\n<tr>\n  <td></td>\n  <td>Page 2</td>\n  <td>Zoom Percent</td>\n  <td>120%</td>\n  <td>0</td>\n</tr>\n<tr>\n  <td></td>\n  <td>Page 3</td>\n  <td>Tab Depth</td>\n  <td>5</td>\n  <td>4-6</td>\n</tr>\n<tr>\n  <td></td>\n  <td>Page 4</td>\n  <td>Type Speed</td>\n  <td>20</td>\n  <td>15-25</td>\n</tr>\n</tbody>\n</table>\n'

Double pipes are not a problem, and “:” are not taken into account.
I think I can manage this issue in my program, it would just be more convenient to have a compatible Testrail syntax.


#4

Thanks, Romain, sounds good! Please let me know in case any further questions come up, happy to help.

Cheers,
Tobias