git.iko.soy/typeable/pandoc
on master help sign in
Code cleanup in Man writer.
9f14bf7fiddlosopher
Text/Pandoc/Writers/Man.hs+23−22
@@ -51,14 +51,14 @@ pandocToMan opts (Pandoc meta blocks) = do
51 let after = writerIncludeAfter opts
51 let after = writerIncludeAfter opts
52 let before' = if null before then empty else text before
52 let before' = if null before then empty else text before
53 let after' = if null after then empty else text after
53 let after' = if null after then empty else text after
54− (head, foot) <- metaToMan opts meta
54+ (head', foot) <- metaToMan opts meta
55 body <- blockListToMan opts blocks
55 body <- blockListToMan opts blocks
56 (notes, preprocessors) <- get
56 (notes, preprocessors) <- get
57 let preamble = if null preprocessors || not (writerStandalone opts)
57 let preamble = if null preprocessors || not (writerStandalone opts)
58 then empty
58 then empty
59 else text $ ".\\\" " ++ concat (nub preprocessors)
59 else text $ ".\\\" " ++ concat (nub preprocessors)
60 notes' <- notesToMan opts (reverse notes)
60 notes' <- notesToMan opts (reverse notes)
61− return $ preamble $$ head $$ before' $$ body $$ notes' $$ foot $$ after'
61+ return $ preamble $$ head' $$ before' $$ body $$ notes' $$ foot $$ after'
62
62
63-- | Insert bibliographic information into Man header and footer.
63-- | Insert bibliographic information into Man header and footer.
64metaToMan :: WriterOptions -- ^ Options, including Man header
64metaToMan :: WriterOptions -- ^ Options, including Man header
@@ -73,14 +73,14 @@ metaToMan options (Meta title authors date) = do
73 xs -> (text (reverse xs), doubleQuotes empty)
73 xs -> (text (reverse xs), doubleQuotes empty)
74 let extras = map (doubleQuotes . text . removeLeadingTrailingSpace) $
74 let extras = map (doubleQuotes . text . removeLeadingTrailingSpace) $
75 splitBy '|' rest
75 splitBy '|' rest
76− let head = (text ".TH") <+> title' <+> section <+>
76+ let head' = (text ".TH") <+> title' <+> section <+>
77 doubleQuotes (text date) <+> hsep extras
77 doubleQuotes (text date) <+> hsep extras
78 let foot = case length authors of
78 let foot = case length authors of
79 0 -> empty
79 0 -> empty
80 1 -> text ".SH AUTHOR" $$ (text $ joinWithSep ", " authors)
80 1 -> text ".SH AUTHOR" $$ (text $ joinWithSep ", " authors)
81 _ -> text ".SH AUTHORS" $$ (text $ joinWithSep ", " authors)
81 _ -> text ".SH AUTHORS" $$ (text $ joinWithSep ", " authors)
82 return $ if writerStandalone options
82 return $ if writerStandalone options
83− then (head, foot)
83+ then (head', foot)
84 else (empty, empty)
84 else (empty, empty)
85
85
86-- | Return man representation of notes.
86-- | Return man representation of notes.
@@ -114,21 +114,21 @@ escapeCode = escapeStringUsing (manEscapes ++ backslashEscapes "\t ")
114blockToMan :: WriterOptions -- ^ Options
114blockToMan :: WriterOptions -- ^ Options
115 -> Block -- ^ Block element
115 -> Block -- ^ Block element
116 -> State WriterState Doc
116 -> State WriterState Doc
117−blockToMan opts Null = return empty
117+blockToMan _ Null = return empty
118blockToMan opts (Plain inlines) =
118blockToMan opts (Plain inlines) =
119 wrapIfNeeded opts (inlineListToMan opts) inlines
119 wrapIfNeeded opts (inlineListToMan opts) inlines
120blockToMan opts (Para inlines) = do
120blockToMan opts (Para inlines) = do
121 contents <- wrapIfNeeded opts (inlineListToMan opts) inlines
121 contents <- wrapIfNeeded opts (inlineListToMan opts) inlines
122 return $ text ".PP" $$ contents
122 return $ text ".PP" $$ contents
123−blockToMan opts (RawHtml str) = return $ text str
123+blockToMan _ (RawHtml str) = return $ text str
124−blockToMan opts HorizontalRule = return $ text $ ".PP\n * * * * *"
124+blockToMan _ HorizontalRule = return $ text $ ".PP\n * * * * *"
125blockToMan opts (Header level inlines) = do
125blockToMan opts (Header level inlines) = do
126 contents <- inlineListToMan opts inlines
126 contents <- inlineListToMan opts inlines
127 let heading = case level of
127 let heading = case level of
128 1 -> ".SH "
128 1 -> ".SH "
129 _ -> ".SS "
129 _ -> ".SS "
130 return $ text heading <> contents
130 return $ text heading <> contents
131−blockToMan opts (CodeBlock _ str) = return $
131+blockToMan _ (CodeBlock _ str) = return $
132 text ".PP" $$ text "\\f[CR]" $$
132 text ".PP" $$ text "\\f[CR]" $$
133 text ((unlines . map (" " ++) . lines) (escapeCode str)) <> text "\\f[]"
133 text ((unlines . map (" " ++) . lines) (escapeCode str)) <> text "\\f[]"
134blockToMan opts (BlockQuote blocks) = do
134blockToMan opts (BlockQuote blocks) = do
@@ -174,7 +174,7 @@ blockToMan opts (DefinitionList items) = do
174
174
175-- | Convert bullet list item (list of blocks) to man.
175-- | Convert bullet list item (list of blocks) to man.
176bulletListItemToMan :: WriterOptions -> [Block] -> State WriterState Doc
176bulletListItemToMan :: WriterOptions -> [Block] -> State WriterState Doc
177−bulletListItemToMan opts [] = return empty
177+bulletListItemToMan _ [] = return empty
178bulletListItemToMan opts ((Para first):rest) =
178bulletListItemToMan opts ((Para first):rest) =
179 bulletListItemToMan opts ((Plain first):rest)
179 bulletListItemToMan opts ((Plain first):rest)
180bulletListItemToMan opts ((Plain first):rest) = do
180bulletListItemToMan opts ((Plain first):rest) = do
@@ -219,8 +219,9 @@ definitionListItemToMan opts (label, items) = do
219 then return empty
219 then return empty
220 else do
220 else do
221 let (first, rest) = case items of
221 let (first, rest) = case items of
222− ((Para x):y) -> (Plain x,y)
222+ ((Para x):y) -> (Plain x,y)
223− (x:y) -> (x,y)
223+ (x:y) -> (x,y)
224+ [] -> error "items is null"
224 rest' <- mapM (\item -> blockToMan opts item)
225 rest' <- mapM (\item -> blockToMan opts item)
225 rest >>= (return . vcat)
226 rest >>= (return . vcat)
226 first' <- blockToMan opts first
227 first' <- blockToMan opts first
@@ -261,18 +262,18 @@ inlineToMan opts (Quoted SingleQuote lst) = do
261inlineToMan opts (Quoted DoubleQuote lst) = do
262inlineToMan opts (Quoted DoubleQuote lst) = do
262 contents <- inlineListToMan opts lst
263 contents <- inlineListToMan opts lst
263 return $ text "\\[lq]" <> contents <> text "\\[rq]"
264 return $ text "\\[lq]" <> contents <> text "\\[rq]"
264−inlineToMan opts EmDash = return $ text "\\[em]"
265+inlineToMan _ EmDash = return $ text "\\[em]"
265−inlineToMan opts EnDash = return $ text "\\[en]"
266+inlineToMan _ EnDash = return $ text "\\[en]"
266−inlineToMan opts Apostrophe = return $ char '\''
267+inlineToMan _ Apostrophe = return $ char '\''
267−inlineToMan opts Ellipses = return $ text "\\&..."
268+inlineToMan _ Ellipses = return $ text "\\&..."
268−inlineToMan opts (Code str) =
269+inlineToMan _ (Code str) =
269 return $ text $ "\\f[B]" ++ escapeCode str ++ "\\f[]"
270 return $ text $ "\\f[B]" ++ escapeCode str ++ "\\f[]"
270−inlineToMan opts (Str str) = return $ text $ escapeString str
271+inlineToMan _ (Str str) = return $ text $ escapeString str
271inlineToMan opts (Math str) = inlineToMan opts (Code str)
272inlineToMan opts (Math str) = inlineToMan opts (Code str)
272−inlineToMan opts (TeX str) = return empty
273+inlineToMan _ (TeX _) = return empty
273−inlineToMan opts (HtmlInline str) = return $ text $ escapeCode str
274+inlineToMan _ (HtmlInline str) = return $ text $ escapeCode str
274−inlineToMan opts (LineBreak) = return $ text "\n.PD 0\n.P\n.PD\n"
275+inlineToMan _ (LineBreak) = return $ text "\n.PD 0\n.P\n.PD\n"
275−inlineToMan opts Space = return $ char ' '
276+inlineToMan _ Space = return $ char ' '
276inlineToMan opts (Link txt (src, _)) = do
277inlineToMan opts (Link txt (src, _)) = do
277 linktext <- inlineListToMan opts txt
278 linktext <- inlineListToMan opts txt
278 let srcSuffix = if isPrefixOf "mailto:" src then drop 7 src else src
279 let srcSuffix = if isPrefixOf "mailto:" src then drop 7 src else src
@@ -286,7 +287,7 @@ inlineToMan opts (Image alternate (source, tit)) = do
286 else alternate
287 else alternate
287 linkPart <- inlineToMan opts (Link txt (source, tit))
288 linkPart <- inlineToMan opts (Link txt (source, tit))
288 return $ char '[' <> text "IMAGE: " <> linkPart <> char ']'
289 return $ char '[' <> text "IMAGE: " <> linkPart <> char ']'
289−inlineToMan opts (Note contents) = do
290+inlineToMan _ (Note contents) = do
290 modify (\(notes, prep) -> (contents:notes, prep)) -- add to notes in state
291 modify (\(notes, prep) -> (contents:notes, prep)) -- add to notes in state
291 (notes, _) <- get
292 (notes, _) <- get
292 let ref = show $ (length notes)
293 let ref = show $ (length notes)