git.iko.soy/typeable/pandoc
on master help sign in
Textile writer: support start number in ordered lists.

e.g. `#3`. Partially addresses #2465. TBD: reader support.

commit48b68aac43bbd7aed397c01ecc94c703f7b81fa7 authorJohn MacFarlane <jgm@berkeley.edu> dateThu 22 Oct 2015, 12:37 (11 years ago) parent652b60f
1 file changed+18−7
src/Text/Pandoc/Writers/Textile.hs+18−7
src/Text/Pandoc/Writers/Textile.hs+18−7
@@ -44,6 +44,7 @@ import Data.Char ( isSpace )
4444data WriterState = WriterState {
4545 stNotes :: [String] -- Footnotes
4646 , stListLevel :: [Char] -- String at beginning of list items, e.g. "**"
47+ , stStartNum :: Maybe Int -- Start number if first list item
4748 , stUseTags :: Bool -- True if we should use HTML tags because we're in a complex list
4849 }
4950
@@ -51,7 +52,8 @@ data WriterState = WriterState {
5152writeTextile :: WriterOptions -> Pandoc -> String
5253writeTextile opts document =
5354 evalState (pandocToTextile opts document)
54− WriterState { stNotes = [], stListLevel = [], stUseTags = False }
55+ WriterState { stNotes = [], stListLevel = [], stStartNum = Nothing,
56+ stUseTags = False }
5557
5658-- | Return Textile representation of document.
5759pandocToTextile :: WriterOptions -> Pandoc -> State WriterState String
@@ -218,7 +220,7 @@ blockToTextile opts x@(BulletList items) = do
218220 modify $ \s -> s { stListLevel = init (stListLevel s) }
219221 return $ vcat contents ++ (if level > 1 then "" else "\n")
220222
221−blockToTextile opts x@(OrderedList attribs items) = do
223+blockToTextile opts x@(OrderedList attribs@(start, _, _) items) = do
222224 oldUseTags <- liftM stUseTags get
223225 let useTags = oldUseTags || not (isSimpleList x)
224226 if useTags
@@ -227,10 +229,14 @@ blockToTextile opts x@(OrderedList attribs items) = do
227229 return $ "<ol" ++ listAttribsToString attribs ++ ">\n" ++ vcat contents ++
228230 "\n</ol>\n"
229231 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 }
231236 level <- get >>= return . length . stListLevel
232237 contents <- mapM (listItemToTextile opts) items
233− modify $ \s -> s { stListLevel = init (stListLevel s) }
238+ modify $ \s -> s { stListLevel = init (stListLevel s),
239+ stStartNum = Nothing }
234240 return $ vcat contents ++ (if level > 1 then "" else "\n")
235241
236242blockToTextile opts (DefinitionList items) = do
@@ -258,8 +264,13 @@ listItemToTextile opts items = do
258264 if useTags
259265 then return $ "<li>" ++ contents ++ "</li>"
260266 else do
261− marker <- get >>= return . stListLevel
262− return $ marker ++ " " ++ contents
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
273+ Nothing -> return $ marker ++ " " ++ contents
263274
264275-- | Convert definition list item (label, list of blocks) to Textile.
265276definitionListItemToTextile :: WriterOptions
@@ -277,7 +288,7 @@ isSimpleList x =
277288 case x of
278289 BulletList items -> all isSimpleListItem items
279290 OrderedList (num, sty, _) items -> all isSimpleListItem items &&
280− num == 1 && sty `elem` [DefaultStyle, Decimal]
291+ sty `elem` [DefaultStyle, Decimal]
281292 _ -> False
282293
283294-- | True if list item can be handled with the simple wiki syntax. False if