@@ -301,8 +301,9 @@ block = choice [ mempty <$ blanklines
301301
302302-- | Attributes that may be added to figures (like a name or caption).
303303data BlockAttributes = BlockAttributes
304− { blockAttrName :: Maybe String
305− , blockAttrCaption :: Maybe (F Inlines)
304+ { blockAttrName :: Maybe String
305+ , blockAttrCaption :: Maybe (F Inlines)
306+ , blockAttrKeyValues :: [(String, String)]
306307 }
307308
308309stringyMetaAttribute :: (String -> Bool) -> OrgParser (String, String)
@@ -318,21 +319,25 @@ blockAttributes :: OrgParser BlockAttributes
318319blockAttributes = try $ do
319320 kv <- many (stringyMetaAttribute attrCheck)
320321 let caption = foldl' (appendValues "CAPTION") Nothing kv
322+ let kvAttrs = foldl' (appendValues "ATTR_HTML") Nothing kv
321323 let name = lookup "NAME" kv
322324 caption' <- maybe (return Nothing)
323325 (fmap Just . parseFromString parseInlines)
324326 caption
327+ kvAttrs' <- parseFromString keyValues . (++ "\n") $ fromMaybe mempty kvAttrs
325328 return $ BlockAttributes
326329 { blockAttrName = name
327330 , blockAttrCaption = caption'
331+ , blockAttrKeyValues = kvAttrs'
328332 }
329333 where
330334 attrCheck :: String -> Bool
331335 attrCheck attr =
332336 case attr of
333− "NAME" -> True
334− "CAPTION" -> True
335− _ -> False
337+ "NAME" -> True
338+ "CAPTION" -> True
339+ "ATTR_HTML" -> True
340+ _ -> False
336341
337342 appendValues :: String -> Maybe String -> (String, String) -> Maybe String
338343 appendValues attrName accValue (key, value) =
@@ -342,6 +347,21 @@ blockAttributes = try $ do
342347 Just acc -> Just $ acc ++ ' ':value
343348 Nothing -> Just value
344349
350+keyValues :: OrgParser [(String, String)]
351+keyValues = try $
352+ manyTill ((,) <$> key <*> value) newline
353+ where
354+ key :: OrgParser String
355+ key = try $ skipSpaces *> char ':' *> many1 nonspaceChar
356+
357+ value :: OrgParser String
358+ value = skipSpaces *> manyTill anyChar endOfValue
359+
360+ endOfValue :: OrgParser ()
361+ endOfValue =
362+ lookAhead $ (() <$ try (many1 spaceChar <* key))
363+ <|> () <$ P.newline
364+
345365
346366--
347367-- Org Blocks (#+BEGIN_... / #+END_...)
@@ -588,7 +608,6 @@ drawerEnd = try $
588608-- Figures
589609--
590610
591−
592611-- | Figures (Image on a line by itself, preceded by name and/or caption)
593612figure :: OrgParser (F Blocks)
594613figure = try $ do
@@ -598,7 +617,9 @@ figure = try $ do
598617 guard (isImageFilename src)
599618 let figName = fromMaybe mempty $ blockAttrName figAttrs
600619 let figCaption = fromMaybe mempty $ blockAttrCaption figAttrs
601− return $ (B.para . B.image src (withFigPrefix figName) <$> figCaption)
620+ let figKeyVals = blockAttrKeyValues figAttrs
621+ let attr = (mempty, mempty, figKeyVals)
622+ return $ (B.para . B.imageWith attr src (withFigPrefix figName) <$> figCaption)
602623 where
603624 withFigPrefix cs =
604625 if "fig:" `isPrefixOf` cs