@@ -103,9 +103,16 @@ escapeNbsp str =
103 let (a,b) = break (=='\160') str in
103 let (a,b) = break (=='\160') str in
104 a ++ escapeNbsp b
104 a ++ escapeNbsp b
106+-- | Escape single quote as \[aq]
107+escapeSingleQuote "" = ""
108+escapeSingleQuote ('\'':xs) = "\\[aq]" ++ escapeSingleQuote xs
109+escapeSingleQuote str =
110+ let (a,b) = break (=='\160') str in
111+ a ++ escapeSingleQuote b
106-- | Escape special characters for Man.
113-- | Escape special characters for Man.
107escapeString :: String -> String
114escapeString :: String -> String
108−escapeString = escapeNbsp . backslashEscape "\"-'.\\"
115+escapeString = escapeSingleQuote . escapeNbsp . backslashEscape "\".-\\"
110-- | Escape a literal (code) section for Man.
117-- | Escape a literal (code) section for Man.
111escapeCode :: String -> String
118escapeCode :: String -> String
@@ -119,21 +126,22 @@ blockToMan opts Null = return empty
119blockToMan opts (Plain inlines) = wrappedMan opts inlines
126blockToMan opts (Plain inlines) = wrappedMan opts inlines
120blockToMan opts (Para inlines) = do
127blockToMan opts (Para inlines) = do
121 contents <- wrappedMan opts inlines
128 contents <- wrappedMan opts inlines
122− return $ text "\n.PP" $$ contents
129+ return $ text ".PP" $$ contents
123blockToMan opts (RawHtml str) = return $ text str
130blockToMan opts (RawHtml str) = return $ text str
124−blockToMan opts HorizontalRule = return $ text $ "\n.PP\n" ++ " * * * * *"
131+blockToMan opts HorizontalRule = return $ text $ ".PP\n * * * * *"
125blockToMan opts (Header level inlines) = do
132blockToMan opts (Header level inlines) = do
126 contents <- inlineListToMan opts inlines
133 contents <- inlineListToMan opts inlines
127 let heading = case level of
134 let heading = case level of
128− 1 -> "\n.SH "
135+ 1 -> ".SH "
129− _ -> "\n.SS "
136+ _ -> ".SS "
130 return $ text heading <> contents
137 return $ text heading <> contents
131blockToMan opts (CodeBlock str) = return $
138blockToMan opts (CodeBlock str) = return $
139+ text ".PP" $$ text "\\f[CR]" $$
132− text "\n\\f[B]" $$ text ((unlines . map (" " ++) . lines) (escapeCode str)) <>
140+ text ((unlines . map (" " ++) . lines) (escapeCode str)) <>
133 text "\\f[]"
141 text "\\f[]"
134blockToMan opts (BlockQuote blocks) = do
142blockToMan opts (BlockQuote blocks) = do
135 contents <- blockListToMan opts blocks
143 contents <- blockListToMan opts blocks
136− return $ text "\n.RS" $$ contents $$ text "\n.RE"
144+ return $ text ".RS" $$ contents $$ text ".RE"
137blockToMan opts (Table caption _ _ headers rows) = blockToMan opts
145blockToMan opts (Table caption _ _ headers rows) = blockToMan opts
138 (Para [Str "pandoc: TABLE unsupported in Man writer"])
146 (Para [Str "pandoc: TABLE unsupported in Man writer"])
@@ -156,15 +164,15 @@ bulletListItemToMan opts ((Para first):rest) =
156bulletListItemToMan opts ((Plain first):rest) = do
164bulletListItemToMan opts ((Plain first):rest) = do
157 first' <- blockToMan opts (Plain first)
165 first' <- blockToMan opts (Plain first)
158 rest' <- blockListToMan opts rest
166 rest' <- blockListToMan opts rest
159− let first'' = text "\n.IP \\[bu] 2" $$ first'
167+ let first'' = text ".IP \\[bu] 2" $$ first'
160 let rest'' = if null rest
168 let rest'' = if null rest
161 then empty
169 then empty
162− else text "\n.RS 2" $$ rest' $$ text "\n.RE"
170+ else text ".RS 2" $$ rest' $$ text ".RE"
163 return (first'' $$ rest'')
171 return (first'' $$ rest'')
164bulletListItemToMan opts (first:rest) = do
172bulletListItemToMan opts (first:rest) = do
165 first' <- blockToMan opts first
173 first' <- blockToMan opts first
166 rest' <- blockListToMan opts rest
174 rest' <- blockListToMan opts rest
167− return $ text "\n\\[bu] \n.RS 2" $$ first' $$ rest' $$ text "\n.RE"
175+ return $ text "\\[bu] .RS 2" $$ first' $$ rest' $$ text ".RE"
169-- | Convert ordered list item (a list of blocks) to man.
177-- | Convert ordered list item (a list of blocks) to man.
170orderedListItemToMan :: WriterOptions -- ^ options
178orderedListItemToMan :: WriterOptions -- ^ options
@@ -177,16 +185,16 @@ orderedListItemToMan opts num ((Para first):rest) =
177orderedListItemToMan opts num ((Plain first):rest) = do
185orderedListItemToMan opts num ((Plain first):rest) = do
178 first' <- blockToMan opts (Plain first)
186 first' <- blockToMan opts (Plain first)
179 rest' <- blockListToMan opts rest
187 rest' <- blockListToMan opts rest
180− let first'' = text ("\n.IP " ++ show num ++ "." ++ " 4") $$ first'
188+ let first'' = text (".IP " ++ show num ++ "." ++ " 4") $$ first'
181 let rest'' = if null rest
189 let rest'' = if null rest
182− then text "\n"
190+ then empty
183− else text "\n.RS 4" $$ rest' $$ text "\n.RE"
191+ else text ".RS 4" $$ rest' $$ text ".RE"
184 return (first'' $$ rest'')
192 return (first'' $$ rest'')
185orderedListItemToMan opts num (first:rest) = do
193orderedListItemToMan opts num (first:rest) = do
186 first' <- blockToMan opts first
194 first' <- blockToMan opts first
187 rest' <- blockListToMan opts rest
195 rest' <- blockListToMan opts rest
188− return $ text ("\n.IP " ++ show num ++ "." ++ " 4") $$ first' $$
196+ return $ text (".IP " ++ show num ++ "." ++ " 4") $$ first' $$
189− rest' $$ text "\n.RE"
197+ rest' $$ text ".RE"
191-- | Convert definition list item (label, list of blocks) to man.
199-- | Convert definition list item (label, list of blocks) to man.
192definitionListItemToMan :: WriterOptions
200definitionListItemToMan :: WriterOptions
@@ -203,8 +211,8 @@ definitionListItemToMan opts (label, items) = do
203 rest' <- mapM (\item -> blockToMan opts item)
211 rest' <- mapM (\item -> blockToMan opts item)
204 rest >>= (return . vcat)
212 rest >>= (return . vcat)
205 first' <- blockToMan opts first
213 first' <- blockToMan opts first
206− return $ first' $$ text "\n.RS" $$ rest' $$ text "\n.RE"
214+ return $ first' $$ text ".RS" $$ rest' $$ text ".RE"
207− return $ text "\n.TP\n.B " <> labelText $+$ contents
215+ return $ text ".TP\n.B " <> labelText $+$ contents
209-- | Convert list of Pandoc block elements to man.
217-- | Convert list of Pandoc block elements to man.
210blockListToMan :: WriterOptions -- ^ Options
218blockListToMan :: WriterOptions -- ^ Options
@@ -240,7 +248,7 @@ inlineToMan opts (Code str) =
240inlineToMan opts (Str str) = return $ text $ escapeString str
248inlineToMan opts (Str str) = return $ text $ escapeString str
241inlineToMan opts (TeX str) = return $ text $ escapeCode str
249inlineToMan opts (TeX str) = return $ text $ escapeCode str
242inlineToMan opts (HtmlInline str) = return $ text $ escapeCode str
250inlineToMan opts (HtmlInline str) = return $ text $ escapeCode str
243−inlineToMan opts (LineBreak) = return $ text "\n.P\n"
251+inlineToMan opts (LineBreak) = return $ text "\n.P 0\n"
244inlineToMan opts Space = return $ char ' '
252inlineToMan opts Space = return $ char ' '
245inlineToMan opts (Link txt (src, _)) = do
253inlineToMan opts (Link txt (src, _)) = do
246 linktext <- inlineListToMan opts txt
254 linktext <- inlineListToMan opts txt