Org reader: allow HTML attribs on non-figure images
Images which are the only element in a paragraph can still be given HTML attributes, even if the image does not have a caption and is hence not a figure. The following will add set the `width` attribute of the image to `50%`: #+ATTR_HTML: :width 50% [[file:image.jpg]] Closes: #3222
This commit is contained in:
parent
13bc573e7f
commit
7e5220b57c
2 changed files with 14 additions and 6 deletions
|
@ -618,7 +618,8 @@ propertiesDrawer = try $ do
|
|||
-- Figures
|
||||
--
|
||||
|
||||
-- | Figures (Image on a line by itself, preceded by name and/or caption)
|
||||
-- | Figures or an image paragraph (i.e. an image on a line by itself). Only
|
||||
-- images with a caption attribute are interpreted as figures.
|
||||
figure :: OrgParser (F Blocks)
|
||||
figure = try $ do
|
||||
figAttrs <- blockAttributes
|
||||
|
@ -626,23 +627,24 @@ figure = try $ do
|
|||
case cleanLinkString src of
|
||||
Nothing -> mzero
|
||||
Just imgSrc -> do
|
||||
guard (not . isNothing . blockAttrCaption $ figAttrs)
|
||||
guard (isImageFilename imgSrc)
|
||||
return $ figureBlock figAttrs imgSrc
|
||||
let isFigure = not . isNothing $ blockAttrCaption figAttrs
|
||||
return $ imageBlock isFigure figAttrs imgSrc
|
||||
where
|
||||
selfTarget :: OrgParser String
|
||||
selfTarget = try $ char '[' *> linkTarget <* char ']'
|
||||
|
||||
figureBlock :: BlockAttributes -> String -> (F Blocks)
|
||||
figureBlock figAttrs imgSrc =
|
||||
imageBlock :: Bool -> BlockAttributes -> String -> F Blocks
|
||||
imageBlock isFigure figAttrs imgSrc =
|
||||
let
|
||||
figName = fromMaybe mempty $ blockAttrName figAttrs
|
||||
figLabel = fromMaybe mempty $ blockAttrLabel figAttrs
|
||||
figCaption = fromMaybe mempty $ blockAttrCaption figAttrs
|
||||
figKeyVals = blockAttrKeyValues figAttrs
|
||||
attr = (figLabel, mempty, figKeyVals)
|
||||
figTitle = (if isFigure then withFigPrefix else id) figName
|
||||
in
|
||||
B.para . B.imageWith attr imgSrc (withFigPrefix figName) <$> figCaption
|
||||
B.para . B.imageWith attr imgSrc figTitle <$> figCaption
|
||||
|
||||
withFigPrefix :: String -> String
|
||||
withFigPrefix cs =
|
||||
|
|
|
@ -196,6 +196,12 @@ tests =
|
|||
"[[file:sunrise.jpg]]" =?>
|
||||
(para $ image "sunrise.jpg" "" "")
|
||||
|
||||
, "Image with html attributes" =:
|
||||
unlines [ "#+ATTR_HTML: :width 50%"
|
||||
, "[[file:guinea-pig.gif]]"
|
||||
] =?>
|
||||
(para $ imageWith ("", [], [("width", "50%")]) "guinea-pig.gif" "" "")
|
||||
|
||||
, "Explicit link" =:
|
||||
"[[http://zeitlens.com/][pseudo-random /nonsense/]]" =?>
|
||||
(para $ link "http://zeitlens.com/" ""
|
||||
|
|
Loading…
Add table
Reference in a new issue