git.iko.soy/typeable/pandoc
on master help sign in
Code cleanup in markdown writer to eliminate -Wall warnings.
ea31c82fiddlosopher
Text/Pandoc/Writers/Markdown.hs+24−25
@@ -55,7 +55,7 @@ pandocToMarkdown opts (Pandoc meta blocks) = do
55 let before' = if null before then empty else text before
55 let before' = if null before then empty else text before
56 let after' = if null after then empty else text after
56 let after' = if null after then empty else text after
57 metaBlock <- metaToMarkdown opts meta
57 metaBlock <- metaToMarkdown opts meta
58− let head = if writerStandalone opts
58+ let head' = if writerStandalone opts
59 then metaBlock $+$ text (writerHeader opts)
59 then metaBlock $+$ text (writerHeader opts)
60 else empty
60 else empty
61 let headerBlocks = filter isHeaderBlock blocks
61 let headerBlocks = filter isHeaderBlock blocks
@@ -67,7 +67,7 @@ pandocToMarkdown opts (Pandoc meta blocks) = do
67 notes' <- notesToMarkdown opts (reverse notes)
67 notes' <- notesToMarkdown opts (reverse notes)
68 (_, refs) <- get -- note that the notes may contain refs
68 (_, refs) <- get -- note that the notes may contain refs
69 refs' <- keyTableToMarkdown opts (reverse refs)
69 refs' <- keyTableToMarkdown opts (reverse refs)
70− return $ head $+$ before' $+$ toc $+$ body $+$ text "" $+$
70+ return $ head' $+$ before' $+$ toc $+$ body $+$ text "" $+$
71 notes' $+$ text "" $+$ refs' $+$ after'
71 notes' $+$ text "" $+$ refs' $+$ after'
72
72
73-- | Return markdown representation of reference key table.
73-- | Return markdown representation of reference key table.
@@ -111,7 +111,7 @@ metaToMarkdown opts (Meta title authors date) = do
111 return $ title' $+$ authors' $+$ date'
111 return $ title' $+$ authors' $+$ date'
112
112
113titleToMarkdown :: WriterOptions -> [Inline] -> State WriterState Doc
113titleToMarkdown :: WriterOptions -> [Inline] -> State WriterState Doc
114−titleToMarkdown opts [] = return empty
114+titleToMarkdown _ [] = return empty
115titleToMarkdown opts lst = do
115titleToMarkdown opts lst = do
116 contents <- inlineListToMarkdown opts lst
116 contents <- inlineListToMarkdown opts lst
117 return $ text "% " <> contents
117 return $ text "% " <> contents
@@ -142,9 +142,9 @@ elementToListItem (Sec headerText subsecs) = [Plain headerText] ++
142
142
143-- | Ordered list start parser for use in Para below.
143-- | Ordered list start parser for use in Para below.
144olMarker :: GenParser Char st Char
144olMarker :: GenParser Char st Char
145−olMarker = do (start, style, delim) <- anyOrderedListMarker
145+olMarker = do (start, style', delim) <- anyOrderedListMarker
146 if delim == Period &&
146 if delim == Period &&
147− (style == UpperAlpha || (style == UpperRoman &&
147+ (style' == UpperAlpha || (style' == UpperRoman &&
148 start `elem` [1, 5, 10, 50, 100, 500, 1000]))
148 start `elem` [1, 5, 10, 50, 100, 500, 1000]))
149 then spaceChar >> spaceChar
149 then spaceChar >> spaceChar
150 else spaceChar
150 else spaceChar
@@ -169,7 +169,7 @@ wrappedMarkdown opts inlines = do
169blockToMarkdown :: WriterOptions -- ^ Options
169blockToMarkdown :: WriterOptions -- ^ Options
170 -> Block -- ^ Block element
170 -> Block -- ^ Block element
171 -> State WriterState Doc
171 -> State WriterState Doc
172−blockToMarkdown opts Null = return empty
172+blockToMarkdown _ Null = return empty
173blockToMarkdown opts (Plain inlines) =
173blockToMarkdown opts (Plain inlines) =
174 wrappedMarkdown opts inlines
174 wrappedMarkdown opts inlines
175blockToMarkdown opts (Para inlines) = do
175blockToMarkdown opts (Para inlines) = do
@@ -180,8 +180,8 @@ blockToMarkdown opts (Para inlines) = do
180 then char '\\'
180 then char '\\'
181 else empty
181 else empty
182 return $ esc <> contents <> text "\n"
182 return $ esc <> contents <> text "\n"
183−blockToMarkdown opts (RawHtml str) = return $ text str
183+blockToMarkdown _ (RawHtml str) = return $ text str
184−blockToMarkdown opts HorizontalRule = return $ text "\n* * * * *\n"
184+blockToMarkdown _ HorizontalRule = return $ text "\n* * * * *\n"
185blockToMarkdown opts (Header level inlines) = do
185blockToMarkdown opts (Header level inlines) = do
186 contents <- inlineListToMarkdown opts inlines
186 contents <- inlineListToMarkdown opts inlines
187 return $ text ((replicate level '#') ++ " ") <> contents <> text "\n"
187 return $ text ((replicate level '#') ++ " ") <> contents <> text "\n"
@@ -205,11 +205,10 @@ blockToMarkdown opts (Table caption aligns widths headers rows) = do
205 AlignDefault -> leftAlignBlock
205 AlignDefault -> leftAlignBlock
206 let makeRow = hsepBlocks . (zipWith alignHeader aligns) .
206 let makeRow = hsepBlocks . (zipWith alignHeader aligns) .
207 (zipWith docToBlock widthsInChars)
207 (zipWith docToBlock widthsInChars)
208− let head = makeRow headers'
208+ let head' = makeRow headers'
209 rows' <- mapM (\row -> do cols <- mapM (blockListToMarkdown opts) row
209 rows' <- mapM (\row -> do cols <- mapM (blockListToMarkdown opts) row
210 return $ makeRow cols) rows
210 return $ makeRow cols) rows
211− let tableWidth = sum widthsInChars
212− let maxRowHeight = maximum $ map heightOfBlock (head:rows')
211+ let maxRowHeight = maximum $ map heightOfBlock (head':rows')
213 let isMultilineTable = maxRowHeight > 1
212 let isMultilineTable = maxRowHeight > 1
214 let underline = hsep $
213 let underline = hsep $
215 map (\width -> text $ replicate width '-') widthsInChars
214 map (\width -> text $ replicate width '-') widthsInChars
@@ -220,7 +219,7 @@ blockToMarkdown opts (Table caption aligns widths headers rows) = do
220 then text ""
219 then text ""
221 else empty
220 else empty
222 let body = vcat $ intersperse spacer $ map blockToDoc rows'
221 let body = vcat $ intersperse spacer $ map blockToDoc rows'
223− return $ (nest 2 $ border $+$ (blockToDoc head) $+$ underline $+$ body $+$
222+ return $ (nest 2 $ border $+$ (blockToDoc head') $+$ underline $+$ body $+$
224 border $+$ caption'') <> text "\n"
223 border $+$ caption'') <> text "\n"
225blockToMarkdown opts (BulletList items) = do
224blockToMarkdown opts (BulletList items) = do
226 contents <- mapM (bulletListItemToMarkdown opts) items
225 contents <- mapM (bulletListItemToMarkdown opts) items
@@ -291,7 +290,7 @@ getReference label (src, tit) = do
291 Just x -> [Str (show x)]
290 Just x -> [Str (show x)]
292 Nothing -> error "no unique label"
291 Nothing -> error "no unique label"
293 Nothing -> label
292 Nothing -> label
294− modify (\(notes, refs) -> (notes, (label', (src,tit)):refs))
293+ modify (\(notes, refs') -> (notes, (label', (src,tit)):refs'))
295 return label'
294 return label'
296
295
297-- | Convert list of Pandoc inline elements to markdown.
296-- | Convert list of Pandoc inline elements to markdown.
@@ -324,11 +323,11 @@ inlineToMarkdown opts (Quoted SingleQuote lst) = do
324inlineToMarkdown opts (Quoted DoubleQuote lst) = do
323inlineToMarkdown opts (Quoted DoubleQuote lst) = do
325 contents <- inlineListToMarkdown opts lst
324 contents <- inlineListToMarkdown opts lst
326 return $ char '"' <> contents <> char '"'
325 return $ char '"' <> contents <> char '"'
327−inlineToMarkdown opts EmDash = return $ text "--"
326+inlineToMarkdown _ EmDash = return $ text "--"
328−inlineToMarkdown opts EnDash = return $ char '-'
327+inlineToMarkdown _ EnDash = return $ char '-'
329−inlineToMarkdown opts Apostrophe = return $ char '\''
328+inlineToMarkdown _ Apostrophe = return $ char '\''
330−inlineToMarkdown opts Ellipses = return $ text "..."
329+inlineToMarkdown _ Ellipses = return $ text "..."
331−inlineToMarkdown opts (Code str) =
330+inlineToMarkdown _ (Code str) =
332 let tickGroups = filter (\s -> '`' `elem` s) $ group str
331 let tickGroups = filter (\s -> '`' `elem` s) $ group str
333 longest = if null tickGroups
332 longest = if null tickGroups
334 then 0
333 then 0
@@ -336,12 +335,12 @@ inlineToMarkdown opts (Code str) =
336 marker = replicate (longest + 1) '`'
335 marker = replicate (longest + 1) '`'
337 spacer = if (longest == 0) then "" else " " in
336 spacer = if (longest == 0) then "" else " " in
338 return $ text (marker ++ spacer ++ str ++ spacer ++ marker)
337 return $ text (marker ++ spacer ++ str ++ spacer ++ marker)
339−inlineToMarkdown opts (Str str) = return $ text $ escapeString str
338+inlineToMarkdown _ (Str str) = return $ text $ escapeString str
340−inlineToMarkdown opts (Math str) = return $ char '$' <> text str <> char '$'
339+inlineToMarkdown _ (Math str) = return $ char '$' <> text str <> char '$'
341−inlineToMarkdown opts (TeX str) = return $ text str
340+inlineToMarkdown _ (TeX str) = return $ text str
342−inlineToMarkdown opts (HtmlInline str) = return $ text str
341+inlineToMarkdown _ (HtmlInline str) = return $ text str
343−inlineToMarkdown opts (LineBreak) = return $ text " \n"
342+inlineToMarkdown _ (LineBreak) = return $ text " \n"
344−inlineToMarkdown opts Space = return $ char ' '
343+inlineToMarkdown _ Space = return $ char ' '
345inlineToMarkdown opts (Link txt (src, tit)) = do
344inlineToMarkdown opts (Link txt (src, tit)) = do
346 linktext <- inlineListToMarkdown opts txt
345 linktext <- inlineListToMarkdown opts txt
347 let linktitle = if null tit then empty else text $ " \"" ++ tit ++ "\""
346 let linktitle = if null tit then empty else text $ " \"" ++ tit ++ "\""
@@ -367,7 +366,7 @@ inlineToMarkdown opts (Image alternate (source, tit)) = do
367 else alternate
366 else alternate
368 linkPart <- inlineToMarkdown opts (Link txt (source, tit))
367 linkPart <- inlineToMarkdown opts (Link txt (source, tit))
369 return $ char '!' <> linkPart
368 return $ char '!' <> linkPart
370−inlineToMarkdown opts (Note contents) = do
369+inlineToMarkdown _ (Note contents) = do
371 modify (\(notes, refs) -> (contents:notes, refs)) -- add to notes in state
370 modify (\(notes, refs) -> (contents:notes, refs)) -- add to notes in state
372 (notes, _) <- get
371 (notes, _) <- get
373 let ref = show $ (length notes)
372 let ref = show $ (length notes)