aboutsummaryrefslogtreecommitdiff
path: root/src/Text
diff options
context:
space:
mode:
authorAlbert Krewinkel <albert@zeitkraut.de>2019-12-13 12:45:55 +0100
committerAlbert Krewinkel <albert@zeitkraut.de>2019-12-13 16:22:04 +0100
commit75dc0130364decfc34a42936d107c24df9532b64 (patch)
tree78f81171d4a1f6609e8e86762fd82fe0b9789ea7 /src/Text
parent2af13ef05aa2b0178ba11184943045cc7782fa0e (diff)
downloadpandoc-75dc0130364decfc34a42936d107c24df9532b64.tar.gz
Org reader: add table labels to caption if both are present
The table `#+NAME:` or `#+LABEL:` is added to the table's caption in the form of an empty span with the label set as the span's ID. Closes: #5984
Diffstat (limited to 'src/Text')
-rw-r--r--src/Text/Pandoc/Readers/Org/Blocks.hs14
1 files changed, 11 insertions, 3 deletions
diff --git a/src/Text/Pandoc/Readers/Org/Blocks.hs b/src/Text/Pandoc/Readers/Org/Blocks.hs
index de51dec3d..785811da8 100644
--- a/src/Text/Pandoc/Readers/Org/Blocks.hs
+++ b/src/Text/Pandoc/Readers/Org/Blocks.hs
@@ -33,7 +33,7 @@ import Text.Pandoc.Definition
import Text.Pandoc.Options
import Text.Pandoc.Shared (compactify, compactifyDL, safeRead)
-import Control.Monad (foldM, guard, mzero, void)
+import Control.Monad (foldM, guard, mplus, mzero, void)
import Data.Char (isSpace)
import Data.Default (Default)
import Data.List (foldl')
@@ -615,8 +615,16 @@ orgTable = try $ do
lookAhead tableStart
do
rows <- tableRows
- let caption = fromMaybe (return mempty) $ blockAttrCaption blockAttrs
- return $ (<$> caption) . orgToPandocTable . normalizeTable =<< rowsToTable rows
+ let captionMb = blockAttrCaption blockAttrs
+ -- amend caption with span as ID tag iff both are present
+ let amendedCaption = do
+ caption' <- captionMb
+ name <- blockAttrName blockAttrs `mplus` blockAttrLabel blockAttrs
+ let tag = B.spanWith (name, mempty, mempty) mempty
+ return $ fmap (tag <>) caption'
+ let caption = fromMaybe mempty (amendedCaption `mplus` captionMb)
+ return $ (<$> caption) . orgToPandocTable . normalizeTable
+ =<< rowsToTable rows
orgToPandocTable :: OrgTable
-> Inlines