@@ -37,8 +37,6 @@ import Data.List ( isPrefixOf, isSuffixOf, drop, intersperse )
37import Text.PrettyPrint.HughesPJ hiding ( Str )
37import Text.PrettyPrint.HughesPJ hiding ( Str )
38import Control.Monad.State
38import Control.Monad.State
40−type Notes = [[Block]]
42data WriterState =
40data WriterState =
43 WriterState { stNotes :: [[Block]]
41 WriterState { stNotes :: [[Block]]
44 , stLinks :: KeyTable
42 , stLinks :: KeyTable
@@ -64,9 +62,9 @@ pandocToRST (Pandoc meta blocks) = do
64 before' = if null before then empty else text before
62 before' = if null before then empty else text before
65 after' = if null after then empty else text after
63 after' = if null after then empty else text after
66 metaBlock <- metaToRST opts meta
64 metaBlock <- metaToRST opts meta
67− let head = if (writerStandalone opts)
65+ let head' = if (writerStandalone opts)
68− then metaBlock $+$ text (writerHeader opts)
66+ then metaBlock $+$ text (writerHeader opts)
69− else empty
67+ else empty
70 body <- blockListToRST blocks
68 body <- blockListToRST blocks
71 includes <- get >>= (return . concat . stIncludes)
69 includes <- get >>= (return . concat . stIncludes)
72 let includes' = if null includes then empty else text includes
70 let includes' = if null includes then empty else text includes
@@ -74,7 +72,7 @@ pandocToRST (Pandoc meta blocks) = do
74 -- note that the notes may contain refs, so we do them first
72 -- note that the notes may contain refs, so we do them first
75 refs <- get >>= (keyTableToRST . reverse . stLinks)
73 refs <- get >>= (keyTableToRST . reverse . stLinks)
76 pics <- get >>= (pictTableToRST . reverse . stImages)
74 pics <- get >>= (pictTableToRST . reverse . stImages)
77− return $ head $+$ before' $+$ includes' $+$ body $+$ notes $+$ text "" $+$
75+ return $ head' $+$ before' $+$ includes' $+$ body $+$ notes $+$ text "" $+$
78 refs $+$ pics $+$ after'
76 refs $+$ pics $+$ after'
80-- | Return RST representation of reference key table.
78-- | Return RST representation of reference key table.
@@ -84,7 +82,7 @@ keyTableToRST refs = mapM keyToRST refs >>= return . vcat
84-- | Return RST representation of a reference key.
82-- | Return RST representation of a reference key.
85keyToRST :: ([Inline], (String, String))
83keyToRST :: ([Inline], (String, String))
86 -> State WriterState Doc
84 -> State WriterState Doc
87−keyToRST (label, (src, tit)) = do
85+keyToRST (label, (src, _)) = do
88 label' <- inlineListToRST label
86 label' <- inlineListToRST label
89 let label'' = if ':' `elem` (render label')
87 let label'' = if ':' `elem` (render label')
90 then char '`' <> label' <> char '`'
88 then char '`' <> label' <> char '`'
@@ -186,46 +184,39 @@ blockToRST (BlockQuote blocks) = do
186 tabstop <- get >>= (return . writerTabStop . stOptions)
184 tabstop <- get >>= (return . writerTabStop . stOptions)
187 contents <- blockListToRST blocks
185 contents <- blockListToRST blocks
188 return $ (nest tabstop contents) <> text "\n"
186 return $ (nest tabstop contents) <> text "\n"
189−blockToRST (Table caption aligns widths headers rows) = do
187+blockToRST (Table caption _ widths headers rows) = do
190 caption' <- inlineListToRST caption
188 caption' <- inlineListToRST caption
191 let caption'' = if null caption
189 let caption'' = if null caption
192 then empty
190 then empty
193 else text "" $+$ (text "Table: " <> caption')
191 else text "" $+$ (text "Table: " <> caption')
194 headers' <- mapM blockListToRST headers
192 headers' <- mapM blockListToRST headers
195 let widthsInChars = map (floor . (78 *)) widths
193 let widthsInChars = map (floor . (78 *)) widths
196− let alignHeader alignment = case alignment of
197− AlignLeft -> leftAlignBlock
198− AlignCenter -> centerAlignBlock
199− AlignRight -> rightAlignBlock
200− AlignDefault -> leftAlignBlock
201 let hpipeBlocks blocks = hcatBlocks [beg, middle, end]
194 let hpipeBlocks blocks = hcatBlocks [beg, middle, end]
202 where height = maximum (map heightOfBlock blocks)
195 where height = maximum (map heightOfBlock blocks)
203− sep = TextBlock 3 height (replicate height " | ")
196+ sep' = TextBlock 3 height (replicate height " | ")
204 beg = TextBlock 2 height (replicate height "| ")
197 beg = TextBlock 2 height (replicate height "| ")
205 end = TextBlock 2 height (replicate height " |")
198 end = TextBlock 2 height (replicate height " |")
206− middle = hcatBlocks $ intersperse sep blocks
199+ middle = hcatBlocks $ intersperse sep' blocks
207 let makeRow = hpipeBlocks . zipWith docToBlock widthsInChars
200 let makeRow = hpipeBlocks . zipWith docToBlock widthsInChars
208− let head = makeRow headers'
201+ let head' = makeRow headers'
209 rows' <- mapM (\row -> do cols <- mapM blockListToRST row
202 rows' <- mapM (\row -> do cols <- mapM blockListToRST row
210 return $ makeRow cols) rows
203 return $ makeRow cols) rows
211− let tableWidth = sum widthsInChars
212− let maxRowHeight = maximum $ map heightOfBlock (head:rows')
213 let border ch = char '+' <> char ch <>
204 let border ch = char '+' <> char ch <>
214 (hcat $ intersperse (char ch <> char '+' <> char ch) $
205 (hcat $ intersperse (char ch <> char '+' <> char ch) $
215 map (\l -> text $ replicate l ch) widthsInChars) <>
206 map (\l -> text $ replicate l ch) widthsInChars) <>
216 char ch <> char '+'
207 char ch <> char '+'
217 let body = vcat $ intersperse (border '-') $ map blockToDoc rows'
208 let body = vcat $ intersperse (border '-') $ map blockToDoc rows'
218− return $ border '-' $+$ blockToDoc head $+$ border '=' $+$ body $+$
209+ return $ border '-' $+$ blockToDoc head' $+$ border '=' $+$ body $+$
219 border '-' $$ caption'' $$ text ""
210 border '-' $$ caption'' $$ text ""
220blockToRST (BulletList items) = do
211blockToRST (BulletList items) = do
221 contents <- mapM bulletListItemToRST items
212 contents <- mapM bulletListItemToRST items
222 -- ensure that sublists have preceding blank line
213 -- ensure that sublists have preceding blank line
223 return $ text "" $+$ vcat contents <> text "\n"
214 return $ text "" $+$ vcat contents <> text "\n"
224−blockToRST (OrderedList (start, style, delim) items) = do
215+blockToRST (OrderedList (start, style', delim) items) = do
225− let markers = if start == 1 && style == DefaultStyle && delim == DefaultDelim
216+ let markers = if start == 1 && style' == DefaultStyle && delim == DefaultDelim
226 then take (length items) $ repeat "#."
217 then take (length items) $ repeat "#."
227 else take (length items) $ orderedListMarkers
218 else take (length items) $ orderedListMarkers
228− (start, style, delim)
219+ (start, style', delim)
229 let maxMarkerLength = maximum $ map length markers
220 let maxMarkerLength = maximum $ map length markers
230 let markers' = map (\m -> let s = maxMarkerLength - length m
221 let markers' = map (\m -> let s = maxMarkerLength - length m
231 in m ++ replicate s ' ') markers
222 in m ++ replicate s ' ') markers
@@ -254,10 +245,10 @@ orderedListItemToRST marker items = do
254-- | Convert defintion list item (label, list of blocks) to RST.
245-- | Convert defintion list item (label, list of blocks) to RST.
255definitionListItemToRST :: ([Inline], [Block]) -> State WriterState Doc
246definitionListItemToRST :: ([Inline], [Block]) -> State WriterState Doc
256definitionListItemToRST (label, items) = do
247definitionListItemToRST (label, items) = do
257− label <- inlineListToRST label
248+ label' <- inlineListToRST label
258 contents <- blockListToRST items
249 contents <- blockListToRST items
259 tabstop <- get >>= (return . writerTabStop . stOptions)
250 tabstop <- get >>= (return . writerTabStop . stOptions)
260− return $ label $+$ nest tabstop contents
251+ return $ label' $+$ nest tabstop contents
262-- | Convert list of Pandoc block elements to RST.
253-- | Convert list of Pandoc block elements to RST.
263blockListToRST :: [Block] -- ^ List of block elements
254blockListToRST :: [Block] -- ^ List of block elements
@@ -305,13 +296,13 @@ inlineToRST (Math str) = do
305 then modify $ \st -> st { stIncludes = rawMathRole : includes }
296 then modify $ \st -> st { stIncludes = rawMathRole : includes }
306 else return ()
297 else return ()
307 return $ text $ ":math:`$" ++ str ++ "$`"
298 return $ text $ ":math:`$" ++ str ++ "$`"
308−inlineToRST (TeX str) = return empty
299+inlineToRST (TeX _) = return empty
309−inlineToRST (HtmlInline str) = return empty
300+inlineToRST (HtmlInline _) = return empty
310inlineToRST (LineBreak) = do
301inlineToRST (LineBreak) = do
311 return $ empty -- there's no line break in RST
302 return $ empty -- there's no line break in RST
312inlineToRST Space = return $ char ' '
303inlineToRST Space = return $ char ' '
313−inlineToRST (Link [Code str] (src, tit)) | src == str ||
304+inlineToRST (Link [Code str] (src, _)) | src == str ||
314− src == "mailto:" ++ str = do
305+ src == "mailto:" ++ str = do
315 let srcSuffix = if isPrefixOf "mailto:" src then drop 7 src else src
306 let srcSuffix = if isPrefixOf "mailto:" src then drop 7 src else src
316 return $ text srcSuffix
307 return $ text srcSuffix
317inlineToRST (Link txt (src, tit)) = do
308inlineToRST (Link txt (src, tit)) = do