summaryrefslogtreecommitdiff
path: root/src/Text
diff options
context:
space:
mode:
authorJohn MacFarlane <jgm@berkeley.edu>2023-12-22 11:14:09 -0800
committerJohn MacFarlane <jgm@berkeley.edu>2023-12-22 11:14:09 -0800
commit81521cee0da35a76a1181e06b83775ba2f94d295 (patch)
treef49f2e5890c5a26faea5c551546e505b94c03e3f /src/Text
parent36d1ec3e45fae278525a0a4cfc5465e4677fe61e (diff)
Markdown writer: add table identifier at end of caption if present.
Suggested at #9279.
Diffstat (limited to 'src/Text')
-rw-r--r--src/Text/Pandoc/Writers/Markdown.hs13
1 files changed, 8 insertions, 5 deletions
diff --git a/src/Text/Pandoc/Writers/Markdown.hs b/src/Text/Pandoc/Writers/Markdown.hs
index 877e54b72..6338a90cd 100644
--- a/src/Text/Pandoc/Writers/Markdown.hs
+++ b/src/Text/Pandoc/Writers/Markdown.hs
@@ -590,16 +590,19 @@ blockToMarkdown' opts (BlockQuote blocks) = do
| otherwise = "> "
contents <- blockListToMarkdown opts blocks
return $ prefixed leader contents <> blankline
-blockToMarkdown' opts t@(Table _ blkCapt specs thead tbody tfoot) = do
+blockToMarkdown' opts t@(Table (ident,_,_) blkCapt specs thead tbody tfoot) = do
let (caption, aligns, widths, headers, rows) = toLegacyTable blkCapt specs thead tbody tfoot
let numcols = maximum (length aligns :| length widths :
map length (headers:rows))
caption' <- inlineListToMarkdown opts caption
- let caption''
+ let caption'' = if T.null ident
+ then caption'
+ else caption' <+> attrsToMarkdown opts (ident,[],[])
+ let caption'''
| null caption = blankline
| isEnabled Ext_table_captions opts
- = blankline $$ (": " <> caption') $$ blankline
- | otherwise = blankline $$ caption' $$ blankline
+ = blankline $$ (": " <> caption'') $$ blankline
+ | otherwise = blankline $$ caption'' $$ blankline
let hasSimpleCells = onlySimpleTableCells $ headers : rows
let isSimple = hasSimpleCells && all (==0) widths
let isPlainBlock (Plain _) = True
@@ -652,7 +655,7 @@ blockToMarkdown' opts t@(Table _ blkCapt specs thead tbody tfoot) = do
literal . removeBlankLinesInHTML <$>
writeHtml5String opts{ writerTemplate = Nothing } (Pandoc nullMeta [t])
| otherwise -> return (id, literal "[TABLE]")
- return $ nst (tbl $$ caption'') $$ blankline
+ return $ nst (tbl $$ caption''') $$ blankline
blockToMarkdown' opts (BulletList items) = do
contents <- inList $ mapM (bulletListItemToMarkdown opts) items
return $ (if isTightList items then vcat else vsep)