aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorfiddlosopher <fiddlosopher@788f1e2b-df1e-0410-8736-df70ead52e1b>2010-03-10 07:34:10 +0000
committerfiddlosopher <fiddlosopher@788f1e2b-df1e-0410-8736-df70ead52e1b>2010-03-10 07:34:10 +0000
commit3b9e7f36ebc04689739b939edb6b3e351a5d0ea7 (patch)
treee970899c8d735acbf1b5dac42d63646223fdb7b5
parent8382de28de003fd9474d94e04b645fdb9236db5b (diff)
downloadpandoc-3b9e7f36ebc04689739b939edb6b3e351a5d0ea7.tar.gz
Markdown writer: proper support for headerless tables.
git-svn-id: https://pandoc.googlecode.com/svn/trunk@1876 788f1e2b-df1e-0410-8736-df70ead52e1b
-rw-r--r--src/Text/Pandoc/Writers/Markdown.hs16
-rw-r--r--tests/tables.markdown19
2 files changed, 31 insertions, 4 deletions
diff --git a/src/Text/Pandoc/Writers/Markdown.hs b/src/Text/Pandoc/Writers/Markdown.hs
index af7ec6e43..96c4fd15d 100644
--- a/src/Text/Pandoc/Writers/Markdown.hs
+++ b/src/Text/Pandoc/Writers/Markdown.hs
@@ -219,20 +219,28 @@ blockToMarkdown opts (Table caption aligns widths headers rows) = do
else map (floor . (78 *)) widths
let makeRow = hsepBlocks . (zipWith alignHeader aligns) .
(zipWith docToBlock widthsInChars)
- let head' = makeRow headers'
let rows' = map makeRow rawRows
+ let head' = makeRow headers'
let maxRowHeight = maximum $ map heightOfBlock (head':rows')
let underline = hsep $
map (\width -> text $ replicate width '-') widthsInChars
let border = if maxRowHeight > 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
then text ""
else empty
let body = vcat $ intersperse spacer $ map blockToDoc rows'
- return $ (nest 2 $ border $+$ (blockToDoc head') $+$ underline $+$ body $+$
- border $+$ caption'') <> text "\n"
+ let bottom = if all null headers
+ then underline
+ else border
+ return $ (nest 2 $ head'' $+$ underline $+$ body $+$
+ bottom $+$ caption'') <> text "\n"
blockToMarkdown opts (BulletList items) = do
contents <- mapM (bulletListItemToMarkdown opts) items
return $ (vcat contents) <> text "\n"
diff --git a/tests/tables.markdown b/tests/tables.markdown
index 4e05cdc35..a605137d1 100644
--- a/tests/tables.markdown
+++ b/tests/tables.markdown
@@ -56,5 +56,24 @@ Multiline table without caption:
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.
+ ----------- ---------- ------------ --------------------------
+