git.iko.soy/typeable/pandoc
on master help sign in
Markdown writer: Use pipe tables if `raw_html` disabled...
506866eJohn MacFarlane
src/Text/Pandoc/Writers/Markdown.hs+10−2
@@ -553,8 +553,13 @@ blockToMarkdown' opts t@(Table caption aligns widths headers rows) = do
553 else blankline $$ (": " <> caption') $$ blankline
553 else blankline $$ (": " <> caption') $$ blankline
554 let isLineBreak LineBreak = Any True
554 let isLineBreak LineBreak = Any True
555 isLineBreak _ = Any False
555 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
558 let isPlainBlock (Plain _) = True
563 let isPlainBlock (Plain _) = True
559 isPlainBlock _ = False
564 isPlainBlock _ = False
560 let hasBlocks = not (all isPlainBlock $ concat . concat $ headers:rows)
565 let hasBlocks = not (all isPlainBlock $ concat . concat $ headers:rows)
@@ -589,6 +594,9 @@ blockToMarkdown' opts t@(Table caption aligns widths headers rows) = do
589 | isEnabled Ext_raw_html opts -> fmap (id,) $
594 | isEnabled Ext_raw_html opts -> fmap (id,) $
590 (text . T.unpack) <$>
595 (text . T.unpack) <$>
591 (writeHtml5String def $ Pandoc nullMeta [t])
596 (writeHtml5String def $ Pandoc nullMeta [t])
597+ | hasSimpleCells &&
598+ isEnabled Ext_pipe_tables opts -> fmap (id,) $
599+ pipeTable (all null headers) aligns' rawHeaders rawRows
592 | otherwise -> return $ (id, text "[TABLE]")
600 | otherwise -> return $ (id, text "[TABLE]")
593 return $ nst $ tbl $$ caption'' $$ blankline
601 return $ nst $ tbl $$ caption'' $$ blankline
594blockToMarkdown' opts (BulletList items) = do
602blockToMarkdown' 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+```