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

[markdown writer] Empty columns in table when first row has only one column #3337

Closed
clopinclopant opened this issue Jan 5, 2017 · 4 comments

Comments

@clopinclopant
Copy link

clopinclopant commented Jan 5, 2017

This looks like an issue in markdown writer.
The file issue.docx when converted to markdown with pandoc-1.19 has the following output:

  --------- ------- -------
  SECTION
  COL A
  --------- ------- -------

while the expected one is:

  --------- ------- -------
  SECTION           
  COL A     COL B   COL C
  --------- ------- -------

(generated from converting file passed.docx).

It seems like the docx reader is getting the data right as the rst writer's output for issue.docx is like expected:

+-----------+---------+---------+
| SECTION   |
+-----------+---------+---------+
| COL A     | COL B   | COL C   |
+-----------+---------+---------+

Thank you for your consideration.
passed.docx

issue.docx

@jgm
Copy link
Owner

jgm commented Jan 5, 2017

% pandoc -t native ~/Downloads/passed.docx 
[Table [] [AlignDefault,AlignDefault,AlignDefault] [0.0,0.0,0.0]
 [[]
 ,[]
 ,[]]
 [[[Plain [Str "SECTION"]]
  ,[]
  ,[]]
 ,[[Plain [Str "COL",Space,Str "A"]]
  ,[Plain [Str "COL",Space,Str "B"]]
  ,[Plain [Str "COL",Space,Str "C"]]]]]
% pandoc -t native ~/Downloads/issue.docx 
[Table [] [AlignDefault] [0.0]
 [[]]
 [[[Plain [Str "SECTION"]]]
 ,[[Plain [Str "COL",Space,Str "A"]]
  ,[Plain [Str "COL",Space,Str "B"]]
  ,[Plain [Str "COL",Space,Str "C"]]]]]

The difference is that in "issue" the header row just has one (empty) cell, while in "passed" it has (as it should) three empty cells. (EDIT: also, in "issue" the first body row has just one cell, while in "passed" it has three, two of them empty.)

So there are two questions:

  1. Why is the docx reader returning a header with just one empty cell? (And a body row with just one cell?)
  2. Why does the markdown writer behave as it does when confronted with this?

@jgm
Copy link
Owner

jgm commented Mar 6, 2017

@jkr Any thoughts about this one? (I mean about question #1 above.)

@jgm
Copy link
Owner

jgm commented Mar 6, 2017

@jkr I think I see now. In the docx file, the first table row (header row) has just one tc element. So I suppose that's why we get what we get.

And indeed, the reader gives output similar to the output the HTML reader gives on

<table>
<tr><td>a</td></tr>
<tr><td>1</td><td>2</td></tr>
</table>

So I think the problem is really just with the markdown writer.

@jgm jgm added this to the pandoc 2.0 milestone Mar 6, 2017
@jgm
Copy link
Owner

jgm commented Mar 6, 2017

On second look, it's a bit more complex. @jkr

In general, when widths and alignments are not explicitly specified, the readers take them from the headers.

So, for example,

% pandoc -f markdown -t native
|a| 
|--|
|b|c|
^D
[Table [] [AlignDefault] [0.0]
 [[Plain [Str "a"]]]
 [[[Plain [Str "b"]]]]]

Here we have alignments and widths for only one column, though the second row has two. (Indeed, the markdown reader goes farther than the HTML or docx readers, and actually truncates the second row.) Similarly

% pandoc -f html -t native
<table>
<tr><td>a</td></tr>
<tr><td>1</td><td>2</td></tr>
</table>
^D
[Table [] [AlignDefault] [0.0]
 []
 [[[Plain [Str "a"]]]
 ,[[Plain [Str "1"]]
  ,[Plain [Str "2"]]]]]

Ideally we'd get alignments and widths for all columns, from every reader. That would be the best solution but would require interventions in most or all readers. (docx, html, markdown all behave the same in this respect.)

Given that we don't, we could work around this in the markdown writer by padding rows that are "light" relative to the longest row, and padding the alignments and widths too. But I'm not positive this wouldn't have some weird effects.

@jgm jgm closed this as completed in 74afd29 Mar 6, 2017
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

3 participants