git.iko.soy/typeable/pandoc
on master help sign in
Implemented bullet lists in asciidoc writer.
commit40c7d096ccbc2f4bb0c0b4b79ba332c2542e997a authorJohn MacFarlane <jgm@berkeley.edu> dateFri 18 Nov 2011, 17:50 (15 years ago) parenta9a4e24
1 file changed+18−21
src/Text/Pandoc/Writers/Asciidoc.hs+18−21
src/Text/Pandoc/Writers/Asciidoc.hs+18−21
@@ -209,8 +209,8 @@ blockToAsciidoc opts (Table caption aligns widths headers rows) = do
209209blockToAsciidoc opts (BulletList items) = do
210210 contents <- mapM (bulletListItemToAsciidoc opts) items
211211 return $ cat contents <> blankline
212−blockToAsciidoc opts (OrderedList attribs items) = do
213− let markers = orderedListMarkers attribs
212+blockToAsciidoc opts (OrderedList (start, sty, _delim) items) = do
213+ let markers = orderedListMarkers (start, sty, Period)
214214 let markers' = map (\m -> if length m < 3
215215 then m ++ replicate (3 - length m) ' '
216216 else m) markers
@@ -223,11 +223,21 @@ blockToAsciidoc opts (DefinitionList items) = do
223223
224224-- | Convert bullet list item (list of blocks) to markdown.
225225bulletListItemToAsciidoc :: WriterOptions -> [Block] -> State WriterState Doc
226−bulletListItemToAsciidoc opts items = do
227− contents <- blockListToAsciidoc opts items
228− let sps = replicate (writerTabStop opts - 2) ' '
229− let start = text ('-' : ' ' : sps)
230− return $ hang (writerTabStop opts) start $ contents <> cr
226+bulletListItemToAsciidoc opts blocks = do
227+ let addBlock :: Doc -> Block -> State WriterState Doc
228+ addBlock d b | isEmpty d = chomp `fmap` blockToAsciidoc opts b
229+ addBlock d b@(BulletList _) = do x <- blockToAsciidoc opts b
230+ return $ d <> cr <> chomp x
231+ addBlock d b@(OrderedList _ _) = do x <- blockToAsciidoc opts b
232+ return $ d <> cr <> chomp x
233+ addBlock d b = do x <- blockToAsciidoc opts b
234+ return $ d <> cr <> text "+" <> cr <> chomp x
235+ lev <- bulletListLevel `fmap` get
236+ modify $ \s -> s{ bulletListLevel = lev + 1 }
237+ contents <- foldM addBlock empty blocks
238+ modify $ \s -> s{ bulletListLevel = lev }
239+ let marker = text (replicate lev '*')
240+ return $ marker <> space <> contents <> cr
231241
232242-- | Convert ordered list item (a list of blocks) to markdown.
233243orderedListItemToAsciidoc :: WriterOptions -- ^ options
@@ -263,20 +273,7 @@ definitionListItemToAsciidoc opts (label, defs) = do
263273blockListToAsciidoc :: WriterOptions -- ^ Options
264274 -> [Block] -- ^ List of block elements
265275 -> State WriterState Doc
266−blockListToAsciidoc opts blocks =
267− mapM (blockToAsciidoc opts) (fixBlocks blocks) >>= return . cat
268− -- insert comment between list and indented code block, or the
269− -- code block will be treated as a list continuation paragraph
270− where fixBlocks (b : CodeBlock attr x : rest)
271− | (attr == nullAttr) && isListBlock b =
272− b : RawBlock "html" "<!-- -->\n" : CodeBlock attr x :
273− fixBlocks rest
274− fixBlocks (x : xs) = x : fixBlocks xs
275− fixBlocks [] = []
276− isListBlock (BulletList _) = True
277− isListBlock (OrderedList _ _) = True
278− isListBlock (DefinitionList _) = True
279− isListBlock _ = False
276+blockListToAsciidoc opts blocks = cat `fmap` mapM (blockToAsciidoc opts) blocks
280277
281278-- | Convert list of Pandoc inline elements to markdown.
282279inlineListToAsciidoc :: WriterOptions -> [Inline] -> State WriterState Doc