From 0f3f5ce1a1569d02dcb858b45dca55cb5d488358 Mon Sep 17 00:00:00 2001
From: Albert Krewinkel <albert@zeitkraut.de>
Date: Sun, 26 Jun 2016 20:19:18 +0200
Subject: Org reader: support figure labels

Figure labels given as `#+LABEL: thelabel` are used as the ID of the
respective image.  This allows e.g. the LaTeX to add proper `\label`
markup.

This fixes half of #2496 and #2999.
---
 src/Text/Pandoc/Readers/Org/Blocks.hs | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

(limited to 'src/Text/Pandoc/Readers/Org')

diff --git a/src/Text/Pandoc/Readers/Org/Blocks.hs b/src/Text/Pandoc/Readers/Org/Blocks.hs
index f8ff3f928..32deb1fc8 100644
--- a/src/Text/Pandoc/Readers/Org/Blocks.hs
+++ b/src/Text/Pandoc/Readers/Org/Blocks.hs
@@ -98,6 +98,7 @@ block = choice [ mempty <$ blanklines
 -- | Attributes that may be added to figures (like a name or caption).
 data BlockAttributes = BlockAttributes
   { blockAttrName      :: Maybe String
+  , blockAttrLabel     :: Maybe String
   , blockAttrCaption   :: Maybe (F Inlines)
   , blockAttrKeyValues :: [(String, String)]
   }
@@ -117,12 +118,14 @@ blockAttributes = try $ do
   let caption = foldl' (appendValues "CAPTION") Nothing kv
   let kvAttrs = foldl' (appendValues "ATTR_HTML") Nothing kv
   let name    = lookup "NAME" kv
+  let label   = lookup "LABEL" kv
   caption' <- maybe (return Nothing)
                     (fmap Just . parseFromString inlines)
                     caption
   kvAttrs' <- parseFromString keyValues . (++ "\n") $ fromMaybe mempty kvAttrs
   return $ BlockAttributes
            { blockAttrName = name
+           , blockAttrLabel = label
            , blockAttrCaption = caption'
            , blockAttrKeyValues = kvAttrs'
            }
@@ -131,6 +134,7 @@ blockAttributes = try $ do
    attrCheck attr =
      case attr of
        "NAME"      -> True
+       "LABEL"     -> True
        "CAPTION"   -> True
        "ATTR_HTML" -> True
        _           -> False
@@ -415,9 +419,10 @@ figure = try $ do
   guard . not . isNothing . blockAttrCaption $ figAttrs
   guard (isImageFilename src)
   let figName    = fromMaybe mempty $ blockAttrName figAttrs
+  let figLabel   = fromMaybe mempty $ blockAttrLabel figAttrs
   let figCaption = fromMaybe mempty $ blockAttrCaption figAttrs
   let figKeyVals = blockAttrKeyValues figAttrs
-  let attr       = (mempty, mempty, figKeyVals)
+  let attr       = (figLabel, mempty, figKeyVals)
   return $ (B.para . B.imageWith attr src (withFigPrefix figName) <$> figCaption)
  where
    withFigPrefix :: String -> String
-- 
cgit v1.2.3