git.iko.soy/typeable/pandoc
on master help sign in
Org reader: allow HTML attribs on non-figure images
7e5220bAlbert Krewinkel
src/Text/Pandoc/Readers/Org/Blocks.hs+8−6
@@ -618,7 +618,8 @@ propertiesDrawer = try $ do
618-- Figures
618-- Figures
619--
619--
620
620
621−-- | Figures (Image on a line by itself, preceded by name and/or caption)
621+-- | Figures or an image paragraph (i.e. an image on a line by itself). Only
622+-- images with a caption attribute are interpreted as figures.
622figure :: OrgParser (F Blocks)
623figure :: OrgParser (F Blocks)
623figure = try $ do
624figure = try $ do
624 figAttrs <- blockAttributes
625 figAttrs <- blockAttributes
@@ -626,23 +627,24 @@ figure = try $ do
626 case cleanLinkString src of
627 case cleanLinkString src of
627 Nothing -> mzero
628 Nothing -> mzero
628 Just imgSrc -> do
629 Just imgSrc -> do
629− guard (not . isNothing . blockAttrCaption $ figAttrs)
630 guard (isImageFilename imgSrc)
630 guard (isImageFilename imgSrc)
631+ let isFigure = not . isNothing $ blockAttrCaption figAttrs
631− return $ figureBlock figAttrs imgSrc
632+ return $ imageBlock isFigure figAttrs imgSrc
632 where
633 where
633 selfTarget :: OrgParser String
634 selfTarget :: OrgParser String
634 selfTarget = try $ char '[' *> linkTarget <* char ']'
635 selfTarget = try $ char '[' *> linkTarget <* char ']'
635
636
636− figureBlock :: BlockAttributes -> String -> (F Blocks)
637+ imageBlock :: Bool -> BlockAttributes -> String -> F Blocks
637− figureBlock figAttrs imgSrc =
638+ imageBlock isFigure figAttrs imgSrc =
638 let
639 let
639 figName = fromMaybe mempty $ blockAttrName figAttrs
640 figName = fromMaybe mempty $ blockAttrName figAttrs
640 figLabel = fromMaybe mempty $ blockAttrLabel figAttrs
641 figLabel = fromMaybe mempty $ blockAttrLabel figAttrs
641 figCaption = fromMaybe mempty $ blockAttrCaption figAttrs
642 figCaption = fromMaybe mempty $ blockAttrCaption figAttrs
642 figKeyVals = blockAttrKeyValues figAttrs
643 figKeyVals = blockAttrKeyValues figAttrs
643 attr = (figLabel, mempty, figKeyVals)
644 attr = (figLabel, mempty, figKeyVals)
645+ figTitle = (if isFigure then withFigPrefix else id) figName
644 in
646 in
645− B.para . B.imageWith attr imgSrc (withFigPrefix figName) <$> figCaption
647+ B.para . B.imageWith attr imgSrc figTitle <$> figCaption
646
648
647 withFigPrefix :: String -> String
649 withFigPrefix :: String -> String
648 withFigPrefix cs =
650 withFigPrefix cs =
tests/Tests/Readers/Org.hs+6
@@ -196,6 +196,12 @@ tests =
196 "[[file:sunrise.jpg]]" =?>
196 "[[file:sunrise.jpg]]" =?>
197 (para $ image "sunrise.jpg" "" "")
197 (para $ image "sunrise.jpg" "" "")
198
198
199+ , "Image with html attributes" =:
200+ unlines [ "#+ATTR_HTML: :width 50%"
201+ , "[[file:guinea-pig.gif]]"
202+ ] =?>
203+ (para $ imageWith ("", [], [("width", "50%")]) "guinea-pig.gif" "" "")
204+
199 , "Explicit link" =:
205 , "Explicit link" =:
200 "[[http://zeitlens.com/][pseudo-random /nonsense/]]" =?>
206 "[[http://zeitlens.com/][pseudo-random /nonsense/]]" =?>
201 (para $ link "http://zeitlens.com/" ""
207 (para $ link "http://zeitlens.com/" ""