git.iko.soy/typeable/pandoc
on master help sign in
Textile writer: support start number in ordered lists.
48b68aaJohn MacFarlane
src/Text/Pandoc/Writers/Textile.hs+18−7
@@ -44,6 +44,7 @@ import Data.Char ( isSpace )
44data WriterState = WriterState {
44data WriterState = WriterState {
45 stNotes :: [String] -- Footnotes
45 stNotes :: [String] -- Footnotes
46 , stListLevel :: [Char] -- String at beginning of list items, e.g. "**"
46 , stListLevel :: [Char] -- String at beginning of list items, e.g. "**"
47+ , stStartNum :: Maybe Int -- Start number if first list item
47 , stUseTags :: Bool -- True if we should use HTML tags because we're in a complex list
48 , stUseTags :: Bool -- True if we should use HTML tags because we're in a complex list
48 }
49 }
49
50
@@ -51,7 +52,8 @@ data WriterState = WriterState {
51writeTextile :: WriterOptions -> Pandoc -> String
52writeTextile :: WriterOptions -> Pandoc -> String
52writeTextile opts document =
53writeTextile opts document =
53 evalState (pandocToTextile opts document)
54 evalState (pandocToTextile opts document)
54− WriterState { stNotes = [], stListLevel = [], stUseTags = False }
55+ WriterState { stNotes = [], stListLevel = [], stStartNum = Nothing,
56+ stUseTags = False }
55
57
56-- | Return Textile representation of document.
58-- | Return Textile representation of document.
57pandocToTextile :: WriterOptions -> Pandoc -> State WriterState String
59pandocToTextile :: WriterOptions -> Pandoc -> State WriterState String
@@ -218,7 +220,7 @@ blockToTextile opts x@(BulletList items) = do
218 modify $ \s -> s { stListLevel = init (stListLevel s) }
220 modify $ \s -> s { stListLevel = init (stListLevel s) }
219 return $ vcat contents ++ (if level > 1 then "" else "\n")
221 return $ vcat contents ++ (if level > 1 then "" else "\n")
220
222
221−blockToTextile opts x@(OrderedList attribs items) = do
223+blockToTextile opts x@(OrderedList attribs@(start, _, _) items) = do
222 oldUseTags <- liftM stUseTags get
224 oldUseTags <- liftM stUseTags get
223 let useTags = oldUseTags || not (isSimpleList x)
225 let useTags = oldUseTags || not (isSimpleList x)
224 if useTags
226 if useTags
@@ -227,10 +229,14 @@ blockToTextile opts x@(OrderedList attribs items) = do
227 return $ "<ol" ++ listAttribsToString attribs ++ ">\n" ++ vcat contents ++
229 return $ "<ol" ++ listAttribsToString attribs ++ ">\n" ++ vcat contents ++
228 "\n</ol>\n"
230 "\n</ol>\n"
229 else do
231 else do
230− modify $ \s -> s { stListLevel = stListLevel s ++ "#" }
232+ modify $ \s -> s { stListLevel = stListLevel s ++ "#"
233+ , stStartNum = if start > 1
234+ then Just start
235+ else Nothing }
231 level <- get >>= return . length . stListLevel
236 level <- get >>= return . length . stListLevel
232 contents <- mapM (listItemToTextile opts) items
237 contents <- mapM (listItemToTextile opts) items
233− modify $ \s -> s { stListLevel = init (stListLevel s) }
238+ modify $ \s -> s { stListLevel = init (stListLevel s),
239+ stStartNum = Nothing }
234 return $ vcat contents ++ (if level > 1 then "" else "\n")
240 return $ vcat contents ++ (if level > 1 then "" else "\n")
235
241
236blockToTextile opts (DefinitionList items) = do
242blockToTextile opts (DefinitionList items) = do
@@ -258,8 +264,13 @@ listItemToTextile opts items = do
258 if useTags
264 if useTags
259 then return $ "<li>" ++ contents ++ "</li>"
265 then return $ "<li>" ++ contents ++ "</li>"
260 else do
266 else do
261− marker <- get >>= return . stListLevel
267+ marker <- gets stListLevel
268+ mbstart <- gets stStartNum
269+ case mbstart of
270+ Just n -> do
271+ modify $ \s -> s{ stStartNum = Nothing }
272+ return $ marker ++ show n ++ " " ++ contents
262− return $ marker ++ " " ++ contents
273+ Nothing -> return $ marker ++ " " ++ contents
263
274
264-- | Convert definition list item (label, list of blocks) to Textile.
275-- | Convert definition list item (label, list of blocks) to Textile.
265definitionListItemToTextile :: WriterOptions
276definitionListItemToTextile :: WriterOptions
@@ -277,7 +288,7 @@ isSimpleList x =
277 case x of
288 case x of
278 BulletList items -> all isSimpleListItem items
289 BulletList items -> all isSimpleListItem items
279 OrderedList (num, sty, _) items -> all isSimpleListItem items &&
290 OrderedList (num, sty, _) items -> all isSimpleListItem items &&
280− num == 1 && sty `elem` [DefaultStyle, Decimal]
291+ sty `elem` [DefaultStyle, Decimal]
281 _ -> False
292 _ -> False
282
293
283-- | True if list item can be handled with the simple wiki syntax. False if
294-- | True if list item can be handled with the simple wiki syntax. False if