@@ -66,7 +66,8 @@ writeAsciiDoc opts document =
6666-- | Convert Pandoc to AsciiDoctor compatible AsciiDoc.
6767writeAsciiDoctor :: PandocMonad m => WriterOptions -> Pandoc -> m Text
6868writeAsciiDoctor opts document =
69− evalStateT (pandocToAsciiDoc opts document) defaultWriterState{ asciidoctorVariant = True }
69+ evalStateT (pandocToAsciiDoc opts document)
70+ defaultWriterState{ asciidoctorVariant = True }
7071
7172type ADW = StateT WriterState
7273
@@ -138,9 +139,11 @@ blockToAsciiDoc opts (Div (id',"section":_,_)
138139blockToAsciiDoc opts (Plain inlines) = do
139140 contents <- inlineListToAsciiDoc opts inlines
140141 return $ contents <> blankline
141−blockToAsciiDoc opts (Para [Image attr alt (src,tgt)])
142+blockToAsciiDoc opts (Para [Image attr alternate (src,tgt)])
143+ -- image::images/logo.png[Company logo, title="blah"]
142144 | Just tit <- T.stripPrefix "fig:" tgt
143− = blockToAsciiDoc opts (Para [Image attr alt (src,tit)])
145+ = (\args -> "image::" <> args <> blankline) <$>
146+ imageArguments opts attr alternate src tit
144147blockToAsciiDoc opts (Para inlines) = do
145148 contents <- inlineListToAsciiDoc opts inlines
146149 -- escape if para starts with ordered list marker
@@ -192,7 +195,8 @@ blockToAsciiDoc opts (BlockQuote blocks) = do
192195 let bar = text "____"
193196 return $ bar $$ chomp contents' $$ bar <> blankline
194197blockToAsciiDoc opts (Table _ blkCapt specs thead tbody tfoot) = do
195− let (caption, aligns, widths, headers, rows) = toLegacyTable blkCapt specs thead tbody tfoot
198+ let (caption, aligns, widths, headers, rows) =
199+ toLegacyTable blkCapt specs thead tbody tfoot
196200 caption' <- inlineListToAsciiDoc opts caption
197201 let caption'' = if null caption
198202 then empty
@@ -381,7 +385,10 @@ blockListToAsciiDoc opts blocks =
381385data SpacyLocation = End | Start
382386
383387-- | Convert list of Pandoc inline elements to asciidoc.
384−inlineListToAsciiDoc :: PandocMonad m => WriterOptions -> [Inline] -> ADW m (Doc Text)
388+inlineListToAsciiDoc :: PandocMonad m =>
389+ WriterOptions ->
390+ [Inline] ->
391+ ADW m (Doc Text)
385392inlineListToAsciiDoc opts lst = do
386393 oldIntraword <- gets intraword
387394 setIntraword False
@@ -518,27 +525,8 @@ inlineToAsciiDoc opts (Link _ txt (src, _tit)) = do
518525 return $ if useAuto
519526 then literal srcSuffix
520527 else prefix <> literal src <> "[" <> linktext <> "]"
521−inlineToAsciiDoc opts (Image attr alternate (src, tit)) = do
522−-- image:images/logo.png[Company logo, title="blah"]
523− let txt = if null alternate || (alternate == [Str ""])
524− then [Str "image"]
525− else alternate
526− linktext <- inlineListToAsciiDoc opts txt
527− let linktitle = if T.null tit
528− then empty
529− else ",title=\"" <> literal tit <> "\""
530− showDim dir = case dimension dir attr of
531− Just (Percent a) ->
532− ["scaledwidth=" <> text (show (Percent a))]
533− Just dim ->
534− [text (show dir) <> "=" <> literal (showInPixel opts dim)]
535− Nothing ->
536− []
537− dimList = showDim Width ++ showDim Height
538− dims = if null dimList
539− then empty
540− else "," <> mconcat (intersperse "," dimList)
541− return $ "image:" <> literal src <> "[" <> linktext <> linktitle <> dims <> "]"
528+inlineToAsciiDoc opts (Image attr alternate (src, tit)) =
529+ ("image:" <>) <$> imageArguments opts attr alternate src tit
542530inlineToAsciiDoc opts (Note [Para inlines]) =
543531 inlineToAsciiDoc opts (Note [Plain inlines])
544532inlineToAsciiDoc opts (Note [Plain inlines]) = do
@@ -556,3 +544,30 @@ inlineToAsciiDoc opts (Span (ident,classes,_) ils) = do
556544 let modifier = brackets $ literal $ T.unwords $
557545 [ "#" <> ident | not (T.null ident)] ++ map ("." <>) classes
558546 return $ modifier <> marker <> contents <> marker
547+
548+-- | Provides the arguments for both `image:` and `image::`
549+-- e.g.: sunset.jpg[Sunset,300,200]
550+imageArguments :: PandocMonad m => WriterOptions ->
551+ Attr -> [Inline] -> Text -> Text ->
552+ ADW m (Doc Text)
553+imageArguments opts attr altText src title = do
554+ let txt = if null altText || (altText == [Str ""])
555+ then [Str "image"]
556+ else altText
557+ linktext <- inlineListToAsciiDoc opts txt
558+ let linktitle = if T.null title
559+ then empty
560+ else ",title=\"" <> literal title <> "\""
561+ showDim dir = case dimension dir attr of
562+ Just (Percent a) ->
563+ ["scaledwidth=" <> text (show (Percent a))]
564+ Just dim ->
565+ [text (show dir) <> "=" <>
566+ literal (showInPixel opts dim)]
567+ Nothing ->
568+ []
569+ dimList = showDim Width ++ showDim Height
570+ dims = if null dimList
571+ then empty
572+ else "," <> mconcat (intersperse "," dimList)
573+ return $ literal src <> "[" <> linktext <> linktitle <> dims <> "]"