git.iko.soy/typeable/pandoc
on master help sign in
Markdown writer: Use pipe tables if `raw_html` disabled...

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

commit506866ef7368ed1cae9236bfd8323fde64eeb154 authorJohn MacFarlane <jgm@berkeley.edu> dateSun 13 Aug 2017, 09:52 (9 years ago) parent39066eb
2 files changed+49−2
src/Text/Pandoc/Writers/Markdown.hs+10−2 test/command/3734.md+39
src/Text/Pandoc/Writers/Markdown.hs+10−2
@@ -553,8 +553,13 @@ blockToMarkdown' opts t@(Table caption aligns widths headers rows) = do
553553 else blankline $$ (": " <> caption') $$ blankline
554554 let isLineBreak LineBreak = Any True
555555 isLineBreak _ = Any False
556− let isSimple = all (==0) widths &&
557− not ( getAny (query isLineBreak (headers:rows)) )
556+ let hasLineBreak = getAny . query isLineBreak
557+ let isSimpleCell [Plain ils] = not (hasLineBreak ils)
558+ isSimpleCell [Para ils ] = not (hasLineBreak ils)
559+ isSimpleCell [] = True
560+ isSimpleCell _ = False
561+ let hasSimpleCells = all isSimpleCell (concat (headers:rows))
562+ let isSimple = hasSimpleCells && all (==0) widths
558563 let isPlainBlock (Plain _) = True
559564 isPlainBlock _ = False
560565 let hasBlocks = not (all isPlainBlock $ concat . concat $ headers:rows)
@@ -589,6 +594,9 @@ blockToMarkdown' opts t@(Table caption aligns widths headers rows) = do
589594 | isEnabled Ext_raw_html opts -> fmap (id,) $
590595 (text . T.unpack) <$>
591596 (writeHtml5String def $ Pandoc nullMeta [t])
597+ | hasSimpleCells &&
598+ isEnabled Ext_pipe_tables opts -> fmap (id,) $
599+ pipeTable (all null headers) aligns' rawHeaders rawRows
592600 | otherwise -> return $ (id, text "[TABLE]")
593601 return $ nst $ tbl $$ caption'' $$ blankline
594602blockToMarkdown' opts (BulletList items) = do
test/command/3734.mdnew file+39
@@ -0,0 +1,39 @@
1+```
2+% pandoc -t markdown_strict+pipe_tables
3+| aaaaaaaaaaaa | bbbbb | ccccccccccc |
4+|--------------|-------|--------------------------------------------------------------------------|
5+| aaaaaaaaaaaa | | cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc |
6+^D
7+<table>
8+<colgroup>
9+<col style="width: 15%" />
10+<col style="width: 8%" />
11+<col style="width: 76%" />
12+</colgroup>
13+<thead>
14+<tr class="header">
15+<th>aaaaaaaaaaaa</th>
16+<th>bbbbb</th>
17+<th>ccccccccccc</th>
18+</tr>
19+</thead>
20+<tbody>
21+<tr class="odd">
22+<td>aaaaaaaaaaaa</td>
23+<td></td>
24+<td>cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc</td>
25+</tr>
26+</tbody>
27+</table>
28+```
29+
30+```
31+% pandoc -t markdown_strict+pipe_tables-raw_html
32+| aaaaaaaaaaaa | bbbbb | ccccccccccc |
33+|--------------|-------|--------------------------------------------------------------------------|
34+| aaaaaaaaaaaa | | cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc |
35+^D
36+| aaaaaaaaaaaa | bbbbb | ccccccccccc |
37+|--------------|-------|--------------------------------------------------------------------------|
38+| aaaaaaaaaaaa | | cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc |
39+```