@@ -52,7 +52,8 @@ import qualified Data.Map as M
5252import Data.Aeson (Value(String), fromJSON, toJSON, Result(..))
5353import qualified Data.Text as T
5454import Data.Char (isSpace, isPunctuation)
55−import Text.Pandoc.Class (PandocMonad)
55+import Text.Pandoc.Class (PandocMonad, report)
56+import Text.Pandoc.Logging
5657
5758data WriterState = WriterState { defListMarker :: String
5859 , orderedListLevel :: Int
@@ -62,16 +63,18 @@ data WriterState = WriterState { defListMarker :: String
6263
6364-- | Convert Pandoc to AsciiDoc.
6465writeAsciiDoc :: PandocMonad m => WriterOptions -> Pandoc -> m String
65−writeAsciiDoc opts document = return $
66− evalState (pandocToAsciiDoc opts document) WriterState{
66+writeAsciiDoc opts document =
67+ evalStateT (pandocToAsciiDoc opts document) WriterState{
6768 defListMarker = "::"
6869 , orderedListLevel = 1
6970 , bulletListLevel = 1
7071 , intraword = False
7172 }
7273
74+type ADW = StateT WriterState
75+
7376-- | Return asciidoc representation of document.
74−pandocToAsciiDoc :: WriterOptions -> Pandoc -> State WriterState String
77+pandocToAsciiDoc :: PandocMonad m => WriterOptions -> Pandoc -> ADW m String
7578pandocToAsciiDoc opts (Pandoc meta blocks) = do
7679 let titleblock = not $ null (docTitle meta) && null (docAuthors meta) &&
7780 null (docDate meta)
@@ -123,9 +126,10 @@ beginsWithOrderedListMarker str =
123126 Right _ -> True
124127
125128-- | Convert Pandoc block element to asciidoc.
126−blockToAsciiDoc :: WriterOptions -- ^ Options
129+blockToAsciiDoc :: PandocMonad m
130+ => WriterOptions -- ^ Options
127131 -> Block -- ^ Block element
128− -> State WriterState Doc
132+ -> ADW m Doc
129133blockToAsciiDoc _ Null = return empty
130134blockToAsciiDoc opts (Plain inlines) = do
131135 contents <- inlineListToAsciiDoc opts inlines
@@ -146,9 +150,11 @@ blockToAsciiDoc opts (LineBlock lns) = do
146150 let joinWithLinefeeds = nowrap . mconcat . intersperse cr
147151 contents <- joinWithLinefeeds <$> mapM docify lns
148152 return $ "[verse]" $$ text "--" $$ contents $$ text "--" $$ blankline
149−blockToAsciiDoc _ (RawBlock f s)
153+blockToAsciiDoc _ b@(RawBlock f s)
150154 | f == "asciidoc" = return $ text s
151− | otherwise = return empty
155+ | otherwise = do
156+ report $ BlockNotRendered b
157+ return empty
152158blockToAsciiDoc _ HorizontalRule =
153159 return $ blankline <> text "'''''" <> blankline
154160blockToAsciiDoc opts (Header level (ident,_,_) inlines) = do
@@ -269,9 +275,10 @@ blockToAsciiDoc opts (Div (ident,_,_) bs) = do
269275 return $ identifier $$ contents
270276
271277-- | Convert bullet list item (list of blocks) to asciidoc.
272−bulletListItemToAsciiDoc :: WriterOptions -> [Block] -> State WriterState Doc
278+bulletListItemToAsciiDoc :: PandocMonad m
279+ => WriterOptions -> [Block] -> ADW m Doc
273280bulletListItemToAsciiDoc opts blocks = do
274− let addBlock :: Doc -> Block -> State WriterState Doc
281+ let addBlock :: PandocMonad m => Doc -> Block -> ADW m Doc
275282 addBlock d b | isEmpty d = chomp `fmap` blockToAsciiDoc opts b
276283 addBlock d b@(BulletList _) = do x <- blockToAsciiDoc opts b
277284 return $ d <> cr <> chomp x
@@ -287,13 +294,13 @@ bulletListItemToAsciiDoc opts blocks = do
287294 return $ marker <> text " " <> contents <> cr
288295
289296-- | Convert ordered list item (a list of blocks) to asciidoc.
290−orderedListItemToAsciiDoc :: WriterOptions -- ^ options
297+orderedListItemToAsciiDoc :: PandocMonad m
298+ => WriterOptions -- ^ options
291299 -> String -- ^ list item marker
292300 -> [Block] -- ^ list item (list of blocks)
293− -> State WriterState Doc
301+ -> ADW m Doc
294302orderedListItemToAsciiDoc opts marker blocks = do
295− let addBlock :: Doc -> Block -> State WriterState Doc
296− addBlock d b | isEmpty d = chomp `fmap` blockToAsciiDoc opts b
303+ let addBlock d b | isEmpty d = chomp `fmap` blockToAsciiDoc opts b
297304 addBlock d b@(BulletList _) = do x <- blockToAsciiDoc opts b
298305 return $ d <> cr <> chomp x
299306 addBlock d b@(OrderedList _ _) = do x <- blockToAsciiDoc opts b
@@ -307,9 +314,10 @@ orderedListItemToAsciiDoc opts marker blocks = do
307314 return $ text marker <> text " " <> contents <> cr
308315
309316-- | Convert definition list item (label, list of blocks) to asciidoc.
310−definitionListItemToAsciiDoc :: WriterOptions
317+definitionListItemToAsciiDoc :: PandocMonad m
318+ => WriterOptions
311319 -> ([Inline],[[Block]])
312− -> State WriterState Doc
320+ -> ADW m Doc
313321definitionListItemToAsciiDoc opts (label, defs) = do
314322 labelText <- inlineListToAsciiDoc opts label
315323 marker <- defListMarker `fmap` get
@@ -317,7 +325,7 @@ definitionListItemToAsciiDoc opts (label, defs) = do
317325 then modify (\st -> st{ defListMarker = ";;"})
318326 else modify (\st -> st{ defListMarker = "::"})
319327 let divider = cr <> text "+" <> cr
320− let defsToAsciiDoc :: [Block] -> State WriterState Doc
328+ let defsToAsciiDoc :: PandocMonad m => [Block] -> ADW m Doc
321329 defsToAsciiDoc ds = (vcat . intersperse divider . map chomp)
322330 `fmap` mapM (blockToAsciiDoc opts) ds
323331 defs' <- mapM defsToAsciiDoc defs
@@ -326,15 +334,16 @@ definitionListItemToAsciiDoc opts (label, defs) = do
326334 return $ labelText <> text marker <> cr <> contents <> cr
327335
328336-- | Convert list of Pandoc block elements to asciidoc.
329−blockListToAsciiDoc :: WriterOptions -- ^ Options
337+blockListToAsciiDoc :: PandocMonad m
338+ => WriterOptions -- ^ Options
330339 -> [Block] -- ^ List of block elements
331− -> State WriterState Doc
340+ -> ADW m Doc
332341blockListToAsciiDoc opts blocks = cat `fmap` mapM (blockToAsciiDoc opts) blocks
333342
334343data SpacyLocation = End | Start
335344
336345-- | Convert list of Pandoc inline elements to asciidoc.
337−inlineListToAsciiDoc :: WriterOptions -> [Inline] -> State WriterState Doc
346+inlineListToAsciiDoc :: PandocMonad m => WriterOptions -> [Inline] -> ADW m Doc
338347inlineListToAsciiDoc opts lst = do
339348 oldIntraword <- gets intraword
340349 setIntraword False
@@ -370,14 +379,14 @@ inlineListToAsciiDoc opts lst = do
370379 isSpacy Start (Str (c:_)) = isPunctuation c || isSpace c
371380 isSpacy _ _ = False
372381
373−setIntraword :: Bool -> State WriterState ()
382+setIntraword :: PandocMonad m => Bool -> ADW m ()
374383setIntraword b = modify $ \st -> st{ intraword = b }
375384
376−withIntraword :: State WriterState a -> State WriterState a
385+withIntraword :: PandocMonad m => ADW m a -> ADW m a
377386withIntraword p = setIntraword True *> p <* setIntraword False
378387
379388-- | Convert Pandoc inline element to asciidoc.
380−inlineToAsciiDoc :: WriterOptions -> Inline -> State WriterState Doc
389+inlineToAsciiDoc :: PandocMonad m => WriterOptions -> Inline -> ADW m Doc
381390inlineToAsciiDoc opts (Emph lst) = do
382391 contents <- inlineListToAsciiDoc opts lst
383392 isIntraword <- gets intraword
@@ -409,8 +418,11 @@ inlineToAsciiDoc _ (Math InlineMath str) =
409418 return $ "latexmath:[$" <> text str <> "$]"
410419inlineToAsciiDoc _ (Math DisplayMath str) =
411420 return $ "latexmath:[\\[" <> text str <> "\\]]"
412−inlineToAsciiDoc _ (RawInline f s)
421+inlineToAsciiDoc _ il@(RawInline f s)
413422 | f == "asciidoc" = return $ text s
423+ | otherwise = do
424+ report $ InlineNotRendered il
425+ return empty
414426 | otherwise = return empty
415427inlineToAsciiDoc _ LineBreak = return $ " +" <> cr
416428inlineToAsciiDoc _ Space = return space