diff options
-rw-r--r-- | src/Text/Pandoc/Readers/Org/Blocks.hs | 14 | ||||
-rw-r--r-- | test/Tests/Readers/Org/Block/Figure.hs | 7 |
2 files changed, 18 insertions, 3 deletions
diff --git a/src/Text/Pandoc/Readers/Org/Blocks.hs b/src/Text/Pandoc/Readers/Org/Blocks.hs index 46ddc4257..8ee9c025d 100644 --- a/src/Text/Pandoc/Readers/Org/Blocks.hs +++ b/src/Text/Pandoc/Readers/Org/Blocks.hs @@ -115,10 +115,14 @@ stringyMetaAttribute = try $ do attrValue <- anyLine <|> ("" <$ newline) return (attrName, attrValue) +-- | Parse a set of block attributes. Block attributes are given through +-- lines like @#+CAPTION: block caption@ or @#+ATTR_HTML: :width 20@. +-- Parsing will fail if any line contains an attribute different from +-- those attributes known to work on blocks. blockAttributes :: PandocMonad m => OrgParser m BlockAttributes blockAttributes = try $ do kv <- many stringyMetaAttribute - guard $ all (attrCheck . fst) kv + 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 @@ -134,8 +138,12 @@ blockAttributes = try $ do , blockAttrKeyValues = kvAttrs' } where - attrCheck :: String -> Bool - attrCheck x = x `elem` ["NAME", "LABEL", "CAPTION", "ATTR_HTML", "RESULTS"] + isBlockAttr :: String -> Bool + isBlockAttr = flip elem + [ "NAME", "LABEL", "CAPTION" + , "ATTR_HTML", "ATTR_LATEX" + , "RESULTS" + ] appendValues :: String -> Maybe String -> (String, String) -> Maybe String appendValues attrName accValue (key, value) = diff --git a/test/Tests/Readers/Org/Block/Figure.hs b/test/Tests/Readers/Org/Block/Figure.hs index 2d78bbe9e..d283f71d5 100644 --- a/test/Tests/Readers/Org/Block/Figure.hs +++ b/test/Tests/Readers/Org/Block/Figure.hs @@ -54,6 +54,13 @@ tests = caption = "mah brain just explodid" in para (imageWith (mempty, mempty, kv) "lambdacat.jpg" name caption) + , "LaTeX attributes are ignored" =: + T.unlines [ "#+CAPTION: Attribute after caption" + , "#+ATTR_LATEX: :float nil" + , "[[file:test.png]]" + ] =?> + para (image "test.png" "fig:" "Attribute after caption") + , "Labelled figure" =: T.unlines [ "#+CAPTION: My figure" , "#+LABEL: fig:myfig" |