Markdown writer: Use pipe tables if raw_html disabled...

and `pipe_tables` enabled, even if the table has relative
width information.

Closes #3734.
This commit is contained in:
John MacFarlane 2017-08-13 09:52:37 -07:00
parent 39066eba1d
commit 506866ef73
2 changed files with 49 additions and 2 deletions

View file

@ -553,8 +553,13 @@ blockToMarkdown' opts t@(Table caption aligns widths headers rows) = do
else blankline $$ (": " <> caption') $$ blankline
let isLineBreak LineBreak = Any True
isLineBreak _ = Any False
let isSimple = all (==0) widths &&
not ( getAny (query isLineBreak (headers:rows)) )
let hasLineBreak = getAny . query isLineBreak
let isSimpleCell [Plain ils] = not (hasLineBreak ils)
isSimpleCell [Para ils ] = not (hasLineBreak ils)
isSimpleCell [] = True
isSimpleCell _ = False
let hasSimpleCells = all isSimpleCell (concat (headers:rows))
let isSimple = hasSimpleCells && all (==0) widths
let isPlainBlock (Plain _) = True
isPlainBlock _ = False
let hasBlocks = not (all isPlainBlock $ concat . concat $ headers:rows)
@ -589,6 +594,9 @@ blockToMarkdown' opts t@(Table caption aligns widths headers rows) = do
| isEnabled Ext_raw_html opts -> fmap (id,) $
(text . T.unpack) <$>
(writeHtml5String def $ Pandoc nullMeta [t])
| hasSimpleCells &&
isEnabled Ext_pipe_tables opts -> fmap (id,) $
pipeTable (all null headers) aligns' rawHeaders rawRows
| otherwise -> return $ (id, text "[TABLE]")
return $ nst $ tbl $$ caption'' $$ blankline
blockToMarkdown' opts (BulletList items) = do

39
test/command/3734.md Normal file
View file

@ -0,0 +1,39 @@
```
% pandoc -t markdown_strict+pipe_tables
| aaaaaaaaaaaa | bbbbb | ccccccccccc |
|--------------|-------|--------------------------------------------------------------------------|
| aaaaaaaaaaaa | | cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc |
^D
<table>
<colgroup>
<col style="width: 15%" />
<col style="width: 8%" />
<col style="width: 76%" />
</colgroup>
<thead>
<tr class="header">
<th>aaaaaaaaaaaa</th>
<th>bbbbb</th>
<th>ccccccccccc</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td>aaaaaaaaaaaa</td>
<td></td>
<td>cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc</td>
</tr>
</tbody>
</table>
```
```
% pandoc -t markdown_strict+pipe_tables-raw_html
| aaaaaaaaaaaa | bbbbb | ccccccccccc |
|--------------|-------|--------------------------------------------------------------------------|
| aaaaaaaaaaaa | | cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc |
^D
| aaaaaaaaaaaa | bbbbb | ccccccccccc |
|--------------|-------|--------------------------------------------------------------------------|
| aaaaaaaaaaaa | | cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc |
```