Muse writer: indent simple tables only on the top level
This commit is contained in:
parent
d27384c109
commit
195b3af8b6
2 changed files with 11 additions and 4 deletions
|
@ -171,19 +171,20 @@ simpleTable :: PandocMonad m
|
|||
-> [[TableCell]]
|
||||
-> Muse m Doc
|
||||
simpleTable caption headers rows = do
|
||||
topLevel <- asks envTopLevel
|
||||
caption' <- inlineListToMuse caption
|
||||
headers' <- mapM blockListToMuse headers
|
||||
rows' <- mapM (mapM blockListToMuse) rows
|
||||
let widthsInChars = maximum . map offset <$> transpose (headers' : rows')
|
||||
let hpipeBlocks sep blocks = hcat $ intersperse sep' blocks
|
||||
where sep' = lblock (length sep) $ text sep
|
||||
let makeRow sep = (" " <>) . hpipeBlocks sep . zipWith lblock widthsInChars
|
||||
let makeRow sep = hpipeBlocks sep . zipWith lblock widthsInChars
|
||||
let head' = makeRow " || " headers'
|
||||
rows'' <- mapM (\row -> makeRow rowSeparator <$> mapM blockListToMuse row) rows
|
||||
let body = vcat rows''
|
||||
return $ (if noHeaders then empty else head')
|
||||
return $ (if topLevel then nest 1 else id) ((if noHeaders then empty else head')
|
||||
$$ body
|
||||
$$ (if null caption then empty else " |+ " <> caption' <> " +|")
|
||||
$$ (if null caption then empty else "|+ " <> caption' <> " +|"))
|
||||
$$ blankline
|
||||
where noHeaders = all null headers
|
||||
rowSeparator = if noHeaders then " | " else " | "
|
||||
|
|
|
@ -400,6 +400,12 @@ tests = [ testGroup "block elements"
|
|||
, " Para 2.1 | Para 2.2"
|
||||
, " |+ Table 1 +|"
|
||||
]
|
||||
, "table inside bullet list" =:
|
||||
bulletList [simpleTable [] [[para "foo", para "bar"]
|
||||
,[para "bat", para "baz"]]]
|
||||
=?> unlines [ " - foo | bar"
|
||||
, " bat | baz"
|
||||
]
|
||||
, "table with one column" =:
|
||||
let headers = []
|
||||
rows = [[para "Para 1"]
|
||||
|
|
Loading…
Reference in a new issue