git.iko.soy/typeable/pandoc
on master help sign in
Org reader: accept ATTR_LATEX in block attributes
63c65c8Albert Krewinkel
src/Text/Pandoc/Readers/Org/Blocks.hs+11−3
@@ -115,10 +115,14 @@ stringyMetaAttribute = try $ do
115 attrValue <- anyLine <|> ("" <$ newline)
115 attrValue <- anyLine <|> ("" <$ newline)
116 return (attrName, attrValue)
116 return (attrName, attrValue)
117
117
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.
118blockAttributes :: PandocMonad m => OrgParser m BlockAttributes
122blockAttributes :: PandocMonad m => OrgParser m BlockAttributes
119blockAttributes = try $ do
123blockAttributes = try $ do
120 kv <- many stringyMetaAttribute
124 kv <- many stringyMetaAttribute
121− guard $ all (attrCheck . fst) kv
125+ guard $ all (isBlockAttr . fst) kv
122 let caption = foldl' (appendValues "CAPTION") Nothing kv
126 let caption = foldl' (appendValues "CAPTION") Nothing kv
123 let kvAttrs = foldl' (appendValues "ATTR_HTML") Nothing kv
127 let kvAttrs = foldl' (appendValues "ATTR_HTML") Nothing kv
124 let name = lookup "NAME" kv
128 let name = lookup "NAME" kv
@@ -134,8 +138,12 @@ blockAttributes = try $ do
134 , blockAttrKeyValues = kvAttrs'
138 , blockAttrKeyValues = kvAttrs'
135 }
139 }
136 where
140 where
137− attrCheck :: String -> Bool
141+ isBlockAttr :: String -> Bool
142+ isBlockAttr = flip elem
138− attrCheck x = x `elem` ["NAME", "LABEL", "CAPTION", "ATTR_HTML", "RESULTS"]
143+ [ "NAME", "LABEL", "CAPTION"
144+ , "ATTR_HTML", "ATTR_LATEX"
145+ , "RESULTS"
146+ ]
139
147
140 appendValues :: String -> Maybe String -> (String, String) -> Maybe String
148 appendValues :: String -> Maybe String -> (String, String) -> Maybe String
141 appendValues attrName accValue (key, value) =
149 appendValues attrName accValue (key, value) =
test/Tests/Readers/Org/Block/Figure.hs+7
@@ -54,6 +54,13 @@ tests =
54 caption = "mah brain just explodid"
54 caption = "mah brain just explodid"
55 in para (imageWith (mempty, mempty, kv) "lambdacat.jpg" name caption)
55 in para (imageWith (mempty, mempty, kv) "lambdacat.jpg" name caption)
56
56
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+
57 , "Labelled figure" =:
64 , "Labelled figure" =:
58 T.unlines [ "#+CAPTION: My figure"
65 T.unlines [ "#+CAPTION: My figure"
59 , "#+LABEL: fig:myfig"
66 , "#+LABEL: fig:myfig"