Markdown writer: proper support for headerless tables.
git-svn-id: https://pandoc.googlecode.com/svn/trunk@1876 788f1e2b-df1e-0410-8736-df70ead52e1b
This commit is contained in:
parent
8382de28de
commit
3b9e7f36eb
2 changed files with 31 additions and 4 deletions
|
@ -219,20 +219,28 @@ blockToMarkdown opts (Table caption aligns widths headers rows) = do
|
||||||
else map (floor . (78 *)) widths
|
else map (floor . (78 *)) widths
|
||||||
let makeRow = hsepBlocks . (zipWith alignHeader aligns) .
|
let makeRow = hsepBlocks . (zipWith alignHeader aligns) .
|
||||||
(zipWith docToBlock widthsInChars)
|
(zipWith docToBlock widthsInChars)
|
||||||
let head' = makeRow headers'
|
|
||||||
let rows' = map makeRow rawRows
|
let rows' = map makeRow rawRows
|
||||||
|
let head' = makeRow headers'
|
||||||
let maxRowHeight = maximum $ map heightOfBlock (head':rows')
|
let maxRowHeight = maximum $ map heightOfBlock (head':rows')
|
||||||
let underline = hsep $
|
let underline = hsep $
|
||||||
map (\width -> text $ replicate width '-') widthsInChars
|
map (\width -> text $ replicate width '-') widthsInChars
|
||||||
let border = if maxRowHeight > 1
|
let border = if maxRowHeight > 1
|
||||||
then text $ replicate (sum widthsInChars + (length widthsInChars - 1)) '-'
|
then text $ replicate (sum widthsInChars + (length widthsInChars - 1)) '-'
|
||||||
else empty
|
else if all null headers
|
||||||
|
then underline
|
||||||
|
else empty
|
||||||
|
let head'' = if all null headers
|
||||||
|
then empty
|
||||||
|
else border $+$ blockToDoc head'
|
||||||
let spacer = if maxRowHeight > 1
|
let spacer = if maxRowHeight > 1
|
||||||
then text ""
|
then text ""
|
||||||
else empty
|
else empty
|
||||||
let body = vcat $ intersperse spacer $ map blockToDoc rows'
|
let body = vcat $ intersperse spacer $ map blockToDoc rows'
|
||||||
return $ (nest 2 $ border $+$ (blockToDoc head') $+$ underline $+$ body $+$
|
let bottom = if all null headers
|
||||||
border $+$ caption'') <> text "\n"
|
then underline
|
||||||
|
else border
|
||||||
|
return $ (nest 2 $ head'' $+$ underline $+$ body $+$
|
||||||
|
bottom $+$ caption'') <> text "\n"
|
||||||
blockToMarkdown opts (BulletList items) = do
|
blockToMarkdown opts (BulletList items) = do
|
||||||
contents <- mapM (bulletListItemToMarkdown opts) items
|
contents <- mapM (bulletListItemToMarkdown opts) items
|
||||||
return $ (vcat contents) <> text "\n"
|
return $ (vcat contents) <> text "\n"
|
||||||
|
|
|
@ -56,5 +56,24 @@ Multiline table without caption:
|
||||||
rows.
|
rows.
|
||||||
--------------------------------------------------------------
|
--------------------------------------------------------------
|
||||||
|
|
||||||
|
Table without column headers:
|
||||||
|
|
||||||
|
----- ----- ----- -----
|
||||||
|
12 12 12 12
|
||||||
|
123 123 123 123
|
||||||
|
1 1 1 1
|
||||||
|
----- ----- ----- -----
|
||||||
|
|
||||||
|
Multiline table without column headers:
|
||||||
|
|
||||||
|
----------- ---------- ------------ --------------------------
|
||||||
|
First row 12.0 Example of a row that
|
||||||
|
spans multiple lines.
|
||||||
|
|
||||||
|
Second row 5.0 Here's another one. Note
|
||||||
|
the blank line between
|
||||||
|
rows.
|
||||||
|
----------- ---------- ------------ --------------------------
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue