From 81521cee0da35a76a1181e06b83775ba2f94d295 Mon Sep 17 00:00:00 2001 From: John MacFarlane Date: Fri, 22 Dec 2023 11:14:09 -0800 Subject: Markdown writer: add table identifier at end of caption if present. Suggested at #9279. --- src/Text/Pandoc/Writers/Markdown.hs | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) (limited to 'src/Text') 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) -- cgit v1.2.3