diff options
| author | Albert Krewinkel <[email protected]> | 2023-04-05 14:12:11 +0200 |
|---|---|---|
| committer | Albert Krewinkel <[email protected]> | 2023-04-05 14:50:52 +0200 |
| commit | b8c7678fcff8064cc9d08b6c21f6fb5c9f2a249e (patch) | |
| tree | 4bce35d1b8b84fcbbc862700dd88ac1b2aa3fc9e | |
| parent | ef16a88cdec6e7fb48142ae74ef3811e4fe749a7 (diff) | |
Org reader: treat `#+NAME` as synonym for `#+LABEL`.
Closes: #8578
| -rw-r--r-- | src/Text/Pandoc/Readers/Org/Blocks.hs | 16 | ||||
| -rw-r--r-- | test/Tests/Readers/Org/Block/Figure.hs | 14 |
2 files changed, 14 insertions, 16 deletions
diff --git a/src/Text/Pandoc/Readers/Org/Blocks.hs b/src/Text/Pandoc/Readers/Org/Blocks.hs index fb586f67d..79f0e1238 100644 --- a/src/Text/Pandoc/Readers/Org/Blocks.hs +++ b/src/Text/Pandoc/Readers/Org/Blocks.hs @@ -32,11 +32,11 @@ import Text.Pandoc.Definition import Text.Pandoc.Options import Text.Pandoc.Shared (compactify, compactifyDL, safeRead) -import Control.Monad (foldM, guard, mplus, mzero, void) +import Control.Monad (foldM, guard, mzero, void) import Data.Char (isSpace) import Data.Default (Default) import Data.Functor (($>)) -import Data.List (foldl') +import Data.List (find, foldl') import Data.Maybe (fromMaybe, isJust, isNothing) import Data.Text (Text) import Data.List.NonEmpty (nonEmpty) @@ -97,7 +97,6 @@ horizontalRule = return B.horizontalRule <$ try hline -- | Attributes that may be added to figures (like a name or caption). data BlockAttributes = BlockAttributes { blockAttrName :: Maybe Text - , blockAttrLabel :: Maybe Text , blockAttrCaption :: Maybe (F Inlines) , blockAttrKeyValues :: [(Text, Text)] } @@ -129,13 +128,11 @@ blockAttributes = try $ do guard $ all (isBlockAttr . fst) kv 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 + let name = snd <$> find ((`elem` ["name", "label"]) . fst) (reverse kv) caption' <- traverse (parseFromString inlines . (<> "\n")) caption kvAttrs' <- parseFromString keyValues . (<> "\n") $ fromMaybe mempty kvAttrs return BlockAttributes { blockAttrName = name - , blockAttrLabel = label , blockAttrCaption = caption' , blockAttrKeyValues = kvAttrs' } @@ -487,13 +484,12 @@ figure = try $ do imageBlock isFigure figAttrs imgSrc = let figName = fromMaybe mempty $ blockAttrName figAttrs - figLabel = fromMaybe mempty $ blockAttrLabel figAttrs figCaption = fromMaybe mempty $ blockAttrCaption figAttrs figKeyVals = blockAttrKeyValues figAttrs - attr = (figLabel, mempty, figKeyVals) + attr = (figName, mempty, figKeyVals) in if isFigure then (\c -> B.figureWith attr (B.simpleCaption (B.plain c)) - (B.plain $ B.image imgSrc figName mempty)) + (B.plain $ B.image imgSrc "" mempty)) <$> figCaption else B.para . B.imageWith attr imgSrc figName <$> figCaption @@ -654,7 +650,7 @@ orgTable = try $ do let caption = fromMaybe mempty (blockAttrCaption blockAttrs) let orgTbl = normalizeTable <$> rowsToTable rows - let identMb = blockAttrName blockAttrs `mplus` blockAttrLabel blockAttrs + let identMb = blockAttrName blockAttrs let attr = (fromMaybe mempty identMb, [], blockAttrKeyValues blockAttrs) return $ orgToPandocTable attr <$> orgTbl <*> caption diff --git a/test/Tests/Readers/Org/Block/Figure.hs b/test/Tests/Readers/Org/Block/Figure.hs index 95cb38994..cbaba1f00 100644 --- a/test/Tests/Readers/Org/Block/Figure.hs +++ b/test/Tests/Readers/Org/Block/Figure.hs @@ -26,8 +26,9 @@ tests = , "#+name: ed" , "[[file:edward.jpg]]" ] =?> - figure (plainCaption "A courageous man.") - (plain $ image "edward.jpg" "ed" "") + figureWith ("ed", mempty, mempty) + (plainCaption "A courageous man.") + (plain $ image "edward.jpg" mempty "") , "Figure with no name" =: T.unlines [ "#+caption: I've been through the desert on this" @@ -41,8 +42,9 @@ tests = , "#+name: fig:redqueen" , "[[./the-red-queen.jpg]]" ] =?> - figure (plainCaption "Used as a metapher in evolutionary biology.") - (plain $ image "./the-red-queen.jpg" "fig:redqueen" "") + figureWith ("fig:redqueen", mempty, mempty) + (plainCaption "Used as a metapher in evolutionary biology.") + (plain $ image "./the-red-queen.jpg" mempty "") , "Figure with HTML attributes" =: T.unlines [ "#+caption: mah brain just explodid" @@ -53,8 +55,8 @@ tests = let kv = [("style", "color: blue"), ("role", "button")] name = "lambdacat" capt = plain "mah brain just explodid" - in figureWith (mempty, mempty, kv) (simpleCaption capt) - (plain $ image "lambdacat.jpg" name "") + in figureWith (name, mempty, kv) (simpleCaption capt) + (plain $ image "lambdacat.jpg" mempty "") , "LaTeX attributes are ignored" =: T.unlines [ "#+caption: Attribute after caption" |
