@@ -56,12 +56,13 @@ import Text.Pandoc.Shared
5656import Text.Pandoc.Templates (renderTemplate')
5757import Text.Pandoc.Writers.Shared
5858
59−data WriterState = WriterState { defListMarker :: String
60− , orderedListLevel :: Int
61− , bulletListLevel :: Int
62− , intraword :: Bool
63− , autoIds :: Set.Set String
59+data WriterState = WriterState { defListMarker :: String
60+ , orderedListLevel :: Int
61+ , bulletListLevel :: Int
62+ , intraword :: Bool
63+ , autoIds :: Set.Set String
6464 , asciidoctorVariant :: Bool
65+ , inList :: Bool
6566 , hasMath :: Bool
6667 }
6768
@@ -72,6 +73,7 @@ defaultWriterState = WriterState { defListMarker = "::"
7273 , intraword = False
7374 , autoIds = Set.empty
7475 , asciidoctorVariant = False
76+ , inList = False
7577 , hasMath = False
7678 }
7779
@@ -268,7 +270,10 @@ blockToAsciiDoc opts (Table caption aligns widths headers rows) = do
268270 return $
269271 caption'' $$ tablespec $$ border $$ head'' $$ body $$ border $$ blankline
270272blockToAsciiDoc opts (BulletList items) = do
273+ inlist <- gets inList
274+ modify $ \st -> st{ inList = True }
271275 contents <- mapM (bulletListItemToAsciiDoc opts) items
276+ modify $ \st -> st{ inList = inlist }
272277 return $ cat contents <> blankline
273278blockToAsciiDoc opts (OrderedList (start, sty, _delim) items) = do
274279 let listStyle = case sty of
@@ -280,10 +285,16 @@ blockToAsciiDoc opts (OrderedList (start, sty, _delim) items) = do
280285 let listoptions = case intercalate ", " (listStyle ++ listStart) of
281286 [] -> empty
282287 x -> brackets (text x)
288+ inlist <- gets inList
289+ modify $ \st -> st{ inList = True }
283290 contents <- mapM (orderedListItemToAsciiDoc opts) items
291+ modify $ \st -> st{ inList = inlist }
284292 return $ listoptions $$ cat contents <> blankline
285293blockToAsciiDoc opts (DefinitionList items) = do
294+ inlist <- gets inList
295+ modify $ \st -> st{ inList = True }
286296 contents <- mapM (definitionListItemToAsciiDoc opts) items
297+ modify $ \st -> st{ inList = inlist }
287298 return $ cat contents <> blankline
288299blockToAsciiDoc opts (Div (ident,_,_) bs) = do
289300 let identifier = if null ident then empty else "[[" <> text ident <> "]]"
@@ -299,16 +310,31 @@ bulletListItemToAsciiDoc opts blocks = do
299310 contents <- foldM (addBlock opts) empty blocks
300311 modify $ \s -> s{ bulletListLevel = lev }
301312 let marker = text (replicate (lev + 1) '*')
302− return $ marker <> text " " <> contents <> cr
313+ return $ marker <> text " " <> listBegin blocks <>
314+ contents <> cr
303315
304316addBlock :: PandocMonad m => WriterOptions -> Doc -> Block -> ADW m Doc
305−addBlock opts d b | isEmpty d = chomp `fmap` blockToAsciiDoc opts b
306−addBlock opts d b@(BulletList _) = do x <- blockToAsciiDoc opts b
307− return $ d <> cr <> chomp x
308−addBlock opts d b@(OrderedList _ _) = do x <- blockToAsciiDoc opts b
309− return $ d <> cr <> chomp x
310−addBlock opts d b = do x <- blockToAsciiDoc opts b
311− return $ d <> cr <> text "+" <> cr <> chomp x
317+addBlock opts d b = do
318+ x <- chomp <$> blockToAsciiDoc opts b
319+ return $
320+ case b of
321+ BulletList{} -> d <> cr <> x
322+ OrderedList{} -> d <> cr <> x
323+ Para (Math DisplayMath _:_) -> d <> cr <> x
324+ Plain (Math DisplayMath _:_) -> d <> cr <> x
325+ Para{} | isEmpty d -> x
326+ Plain{} | isEmpty d -> x
327+ _ -> d <> cr <> text "+" <> cr <> x
328+
329+listBegin :: [Block] -> Doc
330+listBegin blocks =
331+ case blocks of
332+ Para (Math DisplayMath _:_) : _ -> "{blank}"
333+ Plain (Math DisplayMath _:_) : _ -> "{blank}"
334+ Para _ : _ -> empty
335+ Plain _ : _ -> empty
336+ _ : _ -> "{blank}"
337+ [] -> "{blank}"
312338
313339-- | Convert ordered list item (a list of blocks) to asciidoc.
314340orderedListItemToAsciiDoc :: PandocMonad m
@@ -321,7 +347,7 @@ orderedListItemToAsciiDoc opts blocks = do
321347 contents <- foldM (addBlock opts) empty blocks
322348 modify $ \s -> s{ orderedListLevel = lev }
323349 let marker = text (replicate (lev + 1) '.')
324− return $ marker <> text " " <> contents <> cr
350+ return $ marker <> text " " <> listBegin blocks <> contents <> cr
325351
326352-- | Convert definition list item (label, list of blocks) to asciidoc.
327353definitionListItemToAsciiDoc :: PandocMonad m
@@ -437,10 +463,13 @@ inlineToAsciiDoc _ (Math DisplayMath str) = do
437463 let content = if isAsciidoctor
438464 then text str
439465 else "\\[" <> text str <> "\\]"
466+ inlist <- gets inList
467+ let sepline = if inlist
468+ then text "+"
469+ else blankline
440470 return $
441− blankline <> "[latexmath]" $$ "++++" $$
442− content
443− $$ "++++" $$ blankline
471+ (cr <> sepline) $$ "[latexmath]" $$ "++++" $$
472+ content $$ "++++" <> cr
444473inlineToAsciiDoc _ il@(RawInline f s)
445474 | f == "asciidoc" = return $ text s
446475 | otherwise = do