git.iko.soy/typeable/pandoc
on master help sign in
Org reader: accept ATTR_LATEX in block attributes

Attributes for LaTeX output are accepted as valid block attributes; however, their values are ignored. Fixes: #5648

commit63c65c89da7fa54c96199cf88bf1769b7088c1ec authorAlbert Krewinkel <albert@zeitkraut.de> dateSun 21 Jul 2019, 23:06 (7 years ago) parent91d4283
2 files changed+18−3
src/Text/Pandoc/Readers/Org/Blocks.hs+11−3 test/Tests/Readers/Org/Block/Figure.hs+7
src/Text/Pandoc/Readers/Org/Blocks.hs+11−3
@@ -115,10 +115,14 @@ stringyMetaAttribute = try $ do
115115 attrValue <- anyLine <|> ("" <$ newline)
116116 return (attrName, attrValue)
117117
118+-- | Parse a set of block attributes. Block attributes are given through
119+-- lines like @#+CAPTION: block caption@ or @#+ATTR_HTML: :width 20@.
120+-- Parsing will fail if any line contains an attribute different from
121+-- those attributes known to work on blocks.
118122blockAttributes :: PandocMonad m => OrgParser m BlockAttributes
119123blockAttributes = try $ do
120124 kv <- many stringyMetaAttribute
121− guard $ all (attrCheck . fst) kv
125+ guard $ all (isBlockAttr . fst) kv
122126 let caption = foldl' (appendValues "CAPTION") Nothing kv
123127 let kvAttrs = foldl' (appendValues "ATTR_HTML") Nothing kv
124128 let name = lookup "NAME" kv
@@ -134,8 +138,12 @@ blockAttributes = try $ do
134138 , blockAttrKeyValues = kvAttrs'
135139 }
136140 where
137− attrCheck :: String -> Bool
138− attrCheck x = x `elem` ["NAME", "LABEL", "CAPTION", "ATTR_HTML", "RESULTS"]
141+ isBlockAttr :: String -> Bool
142+ isBlockAttr = flip elem
143+ [ "NAME", "LABEL", "CAPTION"
144+ , "ATTR_HTML", "ATTR_LATEX"
145+ , "RESULTS"
146+ ]
139147
140148 appendValues :: String -> Maybe String -> (String, String) -> Maybe String
141149 appendValues attrName accValue (key, value) =
test/Tests/Readers/Org/Block/Figure.hs+7
@@ -54,6 +54,13 @@ tests =
5454 caption = "mah brain just explodid"
5555 in para (imageWith (mempty, mempty, kv) "lambdacat.jpg" name caption)
5656
57+ , "LaTeX attributes are ignored" =:
58+ T.unlines [ "#+CAPTION: Attribute after caption"
59+ , "#+ATTR_LATEX: :float nil"
60+ , "[[file:test.png]]"
61+ ] =?>
62+ para (image "test.png" "fig:" "Attribute after caption")
63+
5764 , "Labelled figure" =:
5865 T.unlines [ "#+CAPTION: My figure"
5966 , "#+LABEL: fig:myfig"