@@ -52,14 +52,13 @@ import Text.Pandoc.Templates (renderTemplate')
5252import Text.Pandoc.Writers.Shared (defField, metaToJSON)
5353
5454data WriterState = WriterState {
55− stItemNum :: Int,
5655 stIndent :: String, -- Indent after the marker at the beginning of list items
5756 stInTable :: Bool, -- Inside a table
5857 stInLink :: Bool -- Inside a link description
5958 }
6059
6160instance Default WriterState where
62− def = WriterState { stItemNum = 1, stIndent = "", stInTable = False, stInLink = False }
61+ def = WriterState { stIndent = "", stInTable = False, stInLink = False }
6362
6463type ZW = StateT WriterState
6564
@@ -188,7 +187,7 @@ blockToZimWiki opts (BulletList items) = do
188187 return $ vcat contents ++ if null indent then "\n" else ""
189188
190189blockToZimWiki opts (OrderedList _ items) = do
191− contents <- mapM (orderedListItemToZimWiki opts) items
190+ contents <- zipWithM (orderedListItemToZimWiki opts) [1..] items
192191 indent <- gets stIndent
193192 return $ vcat contents ++ if null indent then "\n" else ""
194193
@@ -210,25 +209,24 @@ definitionListItemToZimWiki opts (label, items) = do
210209indentFromHTML :: PandocMonad m => WriterOptions -> String -> ZW m String
211210indentFromHTML _ str = do
212211 indent <- gets stIndent
213− itemnum <- gets stItemNum
214− if "<li>" `isInfixOf` str then return $ indent ++ show itemnum ++ "."
215− else if "</li>" `isInfixOf` str then return "\n"
216− else if "<li value=" `isInfixOf` str then do
217− -- poor man's cut
218− let val = drop 10 $ reverse $ drop 1 $ reverse str
219− --let val = take ((length valls) - 2) valls
220− modify $ \s -> s { stItemNum = read val }
221− return ""
222− else if "<ol>" `isInfixOf` str then do
223− let olcount=countSubStrs "<ol>" str
224− modify $ \s -> s { stIndent = stIndent s ++ replicate olcount '\t', stItemNum = 1 }
225− return ""
226− else if "</ol>" `isInfixOf` str then do
227− let olcount=countSubStrs "/<ol>" str
228− modify $ \s -> s{ stIndent = drop olcount (stIndent s) }
229− return ""
230− else
231− return ""
212+ if "<li>" `isInfixOf` str
213+ then return indent
214+ else if "</li>" `isInfixOf` str
215+ then return "\n"
216+ else if "<li value=" `isInfixOf` str
217+ then return ""
218+ else if "<ol>" `isInfixOf` str
219+ then do
220+ let olcount=countSubStrs "<ol>" str
221+ modify $ \s -> s { stIndent = stIndent s ++
222+ replicate olcount '\t' }
223+ return ""
224+ else if "</ol>" `isInfixOf` str
225+ then do
226+ let olcount=countSubStrs "/<ol>" str
227+ modify $ \s -> s{ stIndent = drop olcount (stIndent s) }
228+ return ""
229+ else return ""
232230
233231countSubStrs :: String -> String -> Int
234232countSubStrs sub str = length $ breakOnAll (pack sub) (pack str)
@@ -250,14 +248,12 @@ listItemToZimWiki opts items = do
250248
251249-- | Convert ordered list item (list of blocks) to ZimWiki.
252250orderedListItemToZimWiki :: PandocMonad m
253− => WriterOptions -> [Block] -> ZW m String
254−orderedListItemToZimWiki opts items = do
251+ => WriterOptions -> Int -> [Block] -> ZW m String
252+orderedListItemToZimWiki opts itemnum items = do
255253 indent <- gets stIndent
256254 modify $ \s -> s { stIndent = indent ++ "\t" }
257255 contents <- blockListToZimWiki opts items
258256 modify $ \s -> s{ stIndent = indent }
259− itemnum <- gets stItemNum
260− --modify $ \s -> s { stItemNum = itemnum + 1 } -- this is not strictly necessary for zim as zim does its own renumbering
261257 return $ indent ++ show itemnum ++ ". " ++ contents
262258
263259-- Auxiliary functions for tables:
@@ -343,8 +339,8 @@ inlineToZimWiki _ (Math mathType str) = return $ delim ++ str ++ delim -- note
343339-- | f == Format "html" = return $ "<html>" ++ str ++ "</html>"
344340inlineToZimWiki opts il@(RawInline f str)
345341 | f == Format "zimwiki" = return str
346− | f == Format "html" = indentFromHTML opts str
347− | otherwise = do
342+ | f == Format "html" = indentFromHTML opts str
343+ | otherwise = do
348344 report $ InlineNotRendered il
349345 return ""
350346