git.iko.soy/typeable/pandoc
on master help sign in
Org reader: add table labels to caption if both are present
75dc013Albert Krewinkel
src/Text/Pandoc/Readers/Org/Blocks.hs+11−3
@@ -33,7 +33,7 @@ import Text.Pandoc.Definition
33import Text.Pandoc.Options
33import Text.Pandoc.Options
34import Text.Pandoc.Shared (compactify, compactifyDL, safeRead)
34import Text.Pandoc.Shared (compactify, compactifyDL, safeRead)
35
35
36−import Control.Monad (foldM, guard, mzero, void)
36+import Control.Monad (foldM, guard, mplus, mzero, void)
37import Data.Char (isSpace)
37import Data.Char (isSpace)
38import Data.Default (Default)
38import Data.Default (Default)
39import Data.List (foldl')
39import Data.List (foldl')
@@ -615,8 +615,16 @@ orgTable = try $ do
615 lookAhead tableStart
615 lookAhead tableStart
616 do
616 do
617 rows <- tableRows
617 rows <- tableRows
618− let caption = fromMaybe (return mempty) $ blockAttrCaption blockAttrs
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)
619− return $ (<$> caption) . orgToPandocTable . normalizeTable =<< rowsToTable rows
626+ return $ (<$> caption) . orgToPandocTable . normalizeTable
627+ =<< rowsToTable rows
620
628
621orgToPandocTable :: OrgTable
629orgToPandocTable :: OrgTable
622 -> Inlines
630 -> Inlines
test/command/3706.md+1−1
@@ -15,7 +15,7 @@ pandoc -f org -t native
15| 2 | La |
15| 2 | La |
16| 3 | La |
16| 3 | La |
17^D
17^D
18−[Table [Str "Lalelu."] [AlignDefault,AlignDefault] [0.0,0.0]
18+[Table [Span ("tab",[],[]) [],Str "Lalelu."] [AlignDefault,AlignDefault] [0.0,0.0]
19 [[Plain [Str "Id"]]
19 [[Plain [Str "Id"]]
20 ,[Plain [Str "Desc"]]]
20 ,[Plain [Str "Desc"]]]
21 [[[Plain [Str "1"]]
21 [[[Plain [Str "1"]]