@@ -17,9 +17,9 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
1717-}
1818
1919{- |
20− Module : Text.Pandoc.Writers.Man
20+ Module : Text.Pandoc.Writers.Man
2121 Copyright : Copyright (C) 2007-2010 John MacFarlane
22− License : GNU GPL, version 2 or above
22+ License : GNU GPL, version 2 or above
2323
2424 Maintainer : John MacFarlane <jgm@berkeley.edu>
2525 Stability : alpha
@@ -44,21 +44,21 @@ data WriterState = WriterState { stNotes :: Notes
4444
4545-- | Convert Pandoc to Man.
4646writeMan :: WriterOptions -> Pandoc -> String
47−writeMan opts document = evalState (pandocToMan opts document) (WriterState [] False)
47+writeMan opts document = evalState (pandocToMan opts document) (WriterState [] False)
4848
4949-- | Return groff man representation of document.
5050pandocToMan :: WriterOptions -> Pandoc -> State WriterState String
5151pandocToMan opts (Pandoc (Meta title authors date) blocks) = do
5252 titleText <- inlineListToMan opts title
5353 authors' <- mapM (inlineListToMan opts) authors
54− date' <- inlineListToMan opts date
54+ date' <- inlineListToMan opts date
5555 let colwidth = if writerWrapText opts
5656 then Just $ writerColumns opts
5757 else Nothing
5858 let render' = render colwidth
5959 let (cmdName, rest) = break (== ' ') $ render' titleText
6060 let (title', section) = case reverse cmdName of
61− (')':d:'(':xs) | d `elem` ['0'..'9'] ->
61+ (')':d:'(':xs) | d `elem` ['0'..'9'] ->
6262 (text (reverse xs), char d)
6363 xs -> (text (reverse xs), doubleQuotes empty)
6464 let description = hsep $
@@ -86,7 +86,7 @@ notesToMan :: WriterOptions -> [[Block]] -> State WriterState Doc
8686notesToMan opts notes =
8787 if null notes
8888 then return empty
89− else mapM (\(num, note) -> noteToMan opts num note) (zip [1..] notes) >>=
89+ else mapM (\(num, note) -> noteToMan opts num note) (zip [1..] notes) >>=
9090 return . (text ".SH NOTES" $$) . vcat
9191
9292-- | Return man representation of a note.
@@ -94,7 +94,7 @@ noteToMan :: WriterOptions -> Int -> [Block] -> State WriterState Doc
9494noteToMan opts num note = do
9595 contents <- blockListToMan opts note
9696 let marker = cr <> text ".SS " <> brackets (text (show num))
97− return $ marker $$ contents
97+ return $ marker $$ contents
9898
9999-- | Association list of characters to escape.
100100manEscapes :: [(Char, String)]
@@ -113,7 +113,7 @@ escapeString = escapeStringUsing manEscapes
113113-- | Escape a literal (code) section for Man.
114114escapeCode :: String -> String
115115escapeCode = concat . intersperse "\n" . map escapeLine . lines where
116− escapeLine codeline =
116+ escapeLine codeline =
117117 case escapeStringUsing (manEscapes ++ backslashEscapes "\t ") codeline of
118118 a@('.':_) -> "\\&" ++ a
119119 b -> b
@@ -150,14 +150,14 @@ splitSentences xs =
150150-- | Convert Pandoc block element to man.
151151blockToMan :: WriterOptions -- ^ Options
152152 -> Block -- ^ Block element
153− -> State WriterState Doc
153+ -> State WriterState Doc
154154blockToMan _ Null = return empty
155−blockToMan opts (Plain inlines) =
155+blockToMan opts (Plain inlines) =
156156 liftM vcat $ mapM (inlineListToMan opts) $ splitSentences inlines
157157blockToMan opts (Para inlines) = do
158158 contents <- liftM vcat $ mapM (inlineListToMan opts) $
159159 splitSentences inlines
160− return $ text ".PP" $$ contents
160+ return $ text ".PP" $$ contents
161161blockToMan _ (RawBlock "man" str) = return $ text str
162162blockToMan _ (RawBlock _ _) = return empty
163163blockToMan _ HorizontalRule = return $ text ".PP" $$ text " * * * * *"
@@ -166,7 +166,7 @@ blockToMan opts (Header level inlines) = do
166166 let heading = case level of
167167 1 -> ".SH "
168168 _ -> ".SS "
169− return $ text heading <> contents
169+ return $ text heading <> contents
170170blockToMan _ (CodeBlock _ str) = return $
171171 text ".IP" $$
172172 text ".nf" $$
@@ -174,10 +174,10 @@ blockToMan _ (CodeBlock _ str) = return $
174174 text (escapeCode str) $$
175175 text "\\f[]" $$
176176 text ".fi"
177−blockToMan opts (BlockQuote blocks) = do
177+blockToMan opts (BlockQuote blocks) = do
178178 contents <- blockListToMan opts blocks
179179 return $ text ".RS" $$ contents $$ text ".RE"
180−blockToMan opts (Table caption alignments widths headers rows) =
180+blockToMan opts (Table caption alignments widths headers rows) =
181181 let aligncode AlignLeft = "l"
182182 aligncode AlignRight = "r"
183183 aligncode AlignCenter = "c"
@@ -190,53 +190,53 @@ blockToMan opts (Table caption alignments widths headers rows) =
190190 else map (printf "w(%0.2fn)" . (70 *)) widths
191191 -- 78n default width - 8n indent = 70n
192192 let coldescriptions = text $ intercalate " "
193− (zipWith (\align width -> aligncode align ++ width)
193+ (zipWith (\align width -> aligncode align ++ width)
194194 alignments iwidths) ++ "."
195195 colheadings <- mapM (blockListToMan opts) headers
196− let makeRow cols = text "T{" $$
197− (vcat $ intersperse (text "T}@T{") cols) $$
196+ let makeRow cols = text "T{" $$
197+ (vcat $ intersperse (text "T}@T{") cols) $$
198198 text "T}"
199199 let colheadings' = if all null headers
200200 then empty
201201 else makeRow colheadings $$ char '_'
202− body <- mapM (\row -> do
202+ body <- mapM (\row -> do
203203 cols <- mapM (blockListToMan opts) row
204204 return $ makeRow cols) rows
205− return $ text ".PP" $$ caption' $$
206− text ".TS" $$ text "tab(@);" $$ coldescriptions $$
205+ return $ text ".PP" $$ caption' $$
206+ text ".TS" $$ text "tab(@);" $$ coldescriptions $$
207207 colheadings' $$ vcat body $$ text ".TE"
208208
209209blockToMan opts (BulletList items) = do
210210 contents <- mapM (bulletListItemToMan opts) items
211− return (vcat contents)
211+ return (vcat contents)
212212blockToMan opts (OrderedList attribs items) = do
213− let markers = take (length items) $ orderedListMarkers attribs
213+ let markers = take (length items) $ orderedListMarkers attribs
214214 let indent = 1 + (maximum $ map length markers)
215215 contents <- mapM (\(num, item) -> orderedListItemToMan opts num indent item) $
216− zip markers items
216+ zip markers items
217217 return (vcat contents)
218−blockToMan opts (DefinitionList items) = do
218+blockToMan opts (DefinitionList items) = do
219219 contents <- mapM (definitionListItemToMan opts) items
220220 return (vcat contents)
221221
222222-- | Convert bullet list item (list of blocks) to man.
223223bulletListItemToMan :: WriterOptions -> [Block] -> State WriterState Doc
224224bulletListItemToMan _ [] = return empty
225−bulletListItemToMan opts ((Para first):rest) =
225+bulletListItemToMan opts ((Para first):rest) =
226226 bulletListItemToMan opts ((Plain first):rest)
227227bulletListItemToMan opts ((Plain first):rest) = do
228− first' <- blockToMan opts (Plain first)
228+ first' <- blockToMan opts (Plain first)
229229 rest' <- blockListToMan opts rest
230230 let first'' = text ".IP \\[bu] 2" $$ first'
231231 let rest'' = if null rest
232232 then empty
233233 else text ".RS 2" $$ rest' $$ text ".RE"
234− return (first'' $$ rest'')
234+ return (first'' $$ rest'')
235235bulletListItemToMan opts (first:rest) = do
236236 first' <- blockToMan opts first
237237 rest' <- blockListToMan opts rest
238238 return $ text "\\[bu] .RS 2" $$ first' $$ rest' $$ text ".RE"
239−
239+
240240-- | Convert ordered list item (a list of blocks) to man.
241241orderedListItemToMan :: WriterOptions -- ^ options
242242 -> String -- ^ order marker for list item
@@ -244,7 +244,7 @@ orderedListItemToMan :: WriterOptions -- ^ options
244244 -> [Block] -- ^ list item (list of blocks)
245245 -> State WriterState Doc
246246orderedListItemToMan _ _ _ [] = return empty
247−orderedListItemToMan opts num indent ((Para first):rest) =
247+orderedListItemToMan opts num indent ((Para first):rest) =
248248 orderedListItemToMan opts num indent ((Plain first):rest)
249249orderedListItemToMan opts num indent (first:rest) = do
250250 first' <- blockToMan opts first
@@ -254,17 +254,17 @@ orderedListItemToMan opts num indent (first:rest) = do
254254 let rest'' = if null rest
255255 then empty
256256 else text ".RS 4" $$ rest' $$ text ".RE"
257− return $ first'' $$ rest''
257+ return $ first'' $$ rest''
258258
259259-- | Convert definition list item (label, list of blocks) to man.
260260definitionListItemToMan :: WriterOptions
261− -> ([Inline],[[Block]])
261+ -> ([Inline],[[Block]])
262262 -> State WriterState Doc
263263definitionListItemToMan opts (label, defs) = do
264264 labelText <- inlineListToMan opts label
265− contents <- if null defs
265+ contents <- if null defs
266266 then return empty
267− else liftM vcat $ forM defs $ \blocks -> do
267+ else liftM vcat $ forM defs $ \blocks -> do
268268 let (first, rest) = case blocks of
269269 ((Para x):y) -> (Plain x,y)
270270 (x:y) -> (x,y)
@@ -278,7 +278,7 @@ definitionListItemToMan opts (label, defs) = do
278278-- | Convert list of Pandoc block elements to man.
279279blockListToMan :: WriterOptions -- ^ Options
280280 -> [Block] -- ^ List of block elements
281− -> State WriterState Doc
281+ -> State WriterState Doc
282282blockListToMan opts blocks =
283283 mapM (blockToMan opts) blocks >>= (return . vcat)
284284
@@ -292,7 +292,7 @@ inlineListToMan opts lst = mapM (inlineToMan opts) lst >>= (return . hcat)
292292
293293-- | Convert Pandoc inline element to man.
294294inlineToMan :: WriterOptions -> Inline -> State WriterState Doc
295−inlineToMan opts (Emph lst) = do
295+inlineToMan opts (Emph lst) = do
296296 contents <- inlineListToMan opts lst
297297 return $ text "\\f[I]" <> contents <> text "\\f[]"
298298inlineToMan opts (Strong lst) = do
@@ -333,16 +333,16 @@ inlineToMan opts (Link txt (src, _)) = do
333333 let srcSuffix = if isPrefixOf "mailto:" src then drop 7 src else src
334334 return $ case txt of
335335 [Code _ s]
336− | s == srcSuffix -> char '<' <> text srcSuffix <> char '>'
336+ | s == srcSuffix -> char '<' <> text srcSuffix <> char '>'
337337 _ -> linktext <> text " (" <> text src <> char ')'
338338inlineToMan opts (Image alternate (source, tit)) = do
339− let txt = if (null alternate) || (alternate == [Str ""]) ||
339+ let txt = if (null alternate) || (alternate == [Str ""]) ||
340340 (alternate == [Str source]) -- to prevent autolinks
341341 then [Str "image"]
342342 else alternate
343− linkPart <- inlineToMan opts (Link txt (source, tit))
343+ linkPart <- inlineToMan opts (Link txt (source, tit))
344344 return $ char '[' <> text "IMAGE: " <> linkPart <> char ']'
345−inlineToMan _ (Note contents) = do
345+inlineToMan _ (Note contents) = do
346346 -- add to notes in state
347347 modify $ \st -> st{ stNotes = contents : stNotes st }
348348 notes <- liftM stNotes get