git.iko.soy/typeable/pandoc
on master help sign in
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

commit75dc0130364decfc34a42936d107c24df9532b64 authorAlbert Krewinkel <albert@zeitkraut.de> dateFri 13 Dec 2019, 12:45 (7 years ago) parent2af13ef
2 files changed+12−4
src/Text/Pandoc/Readers/Org/Blocks.hs+11−3 test/command/3706.md+1−1
src/Text/Pandoc/Readers/Org/Blocks.hs+11−3
@@ -33,7 +33,7 @@ import Text.Pandoc.Definition
3333import Text.Pandoc.Options
3434import Text.Pandoc.Shared (compactify, compactifyDL, safeRead)
3535
36−import Control.Monad (foldM, guard, mzero, void)
36+import Control.Monad (foldM, guard, mplus, mzero, void)
3737import Data.Char (isSpace)
3838import Data.Default (Default)
3939import Data.List (foldl')
@@ -615,8 +615,16 @@ orgTable = try $ do
615615 lookAhead tableStart
616616 do
617617 rows <- tableRows
618− let caption = fromMaybe (return mempty) $ blockAttrCaption blockAttrs
619− return $ (<$> caption) . orgToPandocTable . normalizeTable =<< rowsToTable rows
618+ let captionMb = blockAttrCaption blockAttrs
619+ -- amend caption with span as ID tag iff both are present
620+ let amendedCaption = do
621+ caption' <- captionMb
622+ name <- blockAttrName blockAttrs `mplus` blockAttrLabel blockAttrs
623+ let tag = B.spanWith (name, mempty, mempty) mempty
624+ return $ fmap (tag <>) caption'
625+ let caption = fromMaybe mempty (amendedCaption `mplus` captionMb)
626+ return $ (<$> caption) . orgToPandocTable . normalizeTable
627+ =<< rowsToTable rows
620628
621629orgToPandocTable :: OrgTable
622630 -> Inlines
test/command/3706.md+1−1
@@ -15,7 +15,7 @@ pandoc -f org -t native
1515| 2 | La |
1616| 3 | La |
1717^D
18−[Table [Str "Lalelu."] [AlignDefault,AlignDefault] [0.0,0.0]
18+[Table [Span ("tab",[],[]) [],Str "Lalelu."] [AlignDefault,AlignDefault] [0.0,0.0]
1919 [[Plain [Str "Id"]]
2020 ,[Plain [Str "Desc"]]]
2121 [[[Plain [Str "1"]]