git.iko.soy/typeable/pandoc
on master help sign in
Minor changes in Man writer:

- escape ' as \[aq], because ' can trigger groff commands. - remove unneeded line breaks. - use CR font in code blocks. - use .P 0 for line breaks. git-svn-id: https://pandoc.googlecode.com/svn/trunk@612 788f1e2b-df1e-0410-8736-df70ead52e1b

commitf5a3d444948510802facb3cb577fff4329da24a9 authorfiddlosopher <fiddlosopher@788f1e2b-df1e-0410-8736-df70ead52e1b> dateMon 2 Jul 2007, 02:23 (19 years ago) parent6d6fafd
1 file changed+26−18
src/Text/Pandoc/Writers/Man.hs+26−18
src/Text/Pandoc/Writers/Man.hs+26−18
@@ -103,9 +103,16 @@ escapeNbsp str =
103103 let (a,b) = break (=='\160') str in
104104 a ++ escapeNbsp b
105105
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
112+
106113-- | Escape special characters for Man.
107114escapeString :: String -> String
108−escapeString = escapeNbsp . backslashEscape "\"-'.\\"
115+escapeString = escapeSingleQuote . escapeNbsp . backslashEscape "\".-\\"
109116
110117-- | Escape a literal (code) section for Man.
111118escapeCode :: String -> String
@@ -119,21 +126,22 @@ blockToMan opts Null = return empty
119126blockToMan opts (Plain inlines) = wrappedMan opts inlines
120127blockToMan opts (Para inlines) = do
121128 contents <- wrappedMan opts inlines
122− return $ text "\n.PP" $$ contents
129+ return $ text ".PP" $$ contents
123130blockToMan opts (RawHtml str) = return $ text str
124−blockToMan opts HorizontalRule = return $ text $ "\n.PP\n" ++ " * * * * *"
131+blockToMan opts HorizontalRule = return $ text $ ".PP\n * * * * *"
125132blockToMan opts (Header level inlines) = do
126133 contents <- inlineListToMan opts inlines
127134 let heading = case level of
128− 1 -> "\n.SH "
129− _ -> "\n.SS "
135+ 1 -> ".SH "
136+ _ -> ".SS "
130137 return $ text heading <> contents
131138blockToMan opts (CodeBlock str) = return $
132− text "\n\\f[B]" $$ text ((unlines . map (" " ++) . lines) (escapeCode str)) <>
139+ text ".PP" $$ text "\\f[CR]" $$
140+ text ((unlines . map (" " ++) . lines) (escapeCode str)) <>
133141 text "\\f[]"
134142blockToMan opts (BlockQuote blocks) = do
135143 contents <- blockListToMan opts blocks
136− return $ text "\n.RS" $$ contents $$ text "\n.RE"
144+ return $ text ".RS" $$ contents $$ text ".RE"
137145blockToMan opts (Table caption _ _ headers rows) = blockToMan opts
138146 (Para [Str "pandoc: TABLE unsupported in Man writer"])
139147
@@ -156,15 +164,15 @@ bulletListItemToMan opts ((Para first):rest) =
156164bulletListItemToMan opts ((Plain first):rest) = do
157165 first' <- blockToMan opts (Plain first)
158166 rest' <- blockListToMan opts rest
159− let first'' = text "\n.IP \\[bu] 2" $$ first'
167+ let first'' = text ".IP \\[bu] 2" $$ first'
160168 let rest'' = if null rest
161169 then empty
162− else text "\n.RS 2" $$ rest' $$ text "\n.RE"
170+ else text ".RS 2" $$ rest' $$ text ".RE"
163171 return (first'' $$ rest'')
164172bulletListItemToMan opts (first:rest) = do
165173 first' <- blockToMan opts first
166174 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"
168176
169177-- | Convert ordered list item (a list of blocks) to man.
170178orderedListItemToMan :: WriterOptions -- ^ options
@@ -177,16 +185,16 @@ orderedListItemToMan opts num ((Para first):rest) =
177185orderedListItemToMan opts num ((Plain first):rest) = do
178186 first' <- blockToMan opts (Plain first)
179187 rest' <- blockListToMan opts rest
180− let first'' = text ("\n.IP " ++ show num ++ "." ++ " 4") $$ first'
188+ let first'' = text (".IP " ++ show num ++ "." ++ " 4") $$ first'
181189 let rest'' = if null rest
182− then text "\n"
183− else text "\n.RS 4" $$ rest' $$ text "\n.RE"
190+ then empty
191+ else text ".RS 4" $$ rest' $$ text ".RE"
184192 return (first'' $$ rest'')
185193orderedListItemToMan opts num (first:rest) = do
186194 first' <- blockToMan opts first
187195 rest' <- blockListToMan opts rest
188− return $ text ("\n.IP " ++ show num ++ "." ++ " 4") $$ first' $$
189− rest' $$ text "\n.RE"
196+ return $ text (".IP " ++ show num ++ "." ++ " 4") $$ first' $$
197+ rest' $$ text ".RE"
190198
191199-- | Convert definition list item (label, list of blocks) to man.
192200definitionListItemToMan :: WriterOptions
@@ -203,8 +211,8 @@ definitionListItemToMan opts (label, items) = do
203211 rest' <- mapM (\item -> blockToMan opts item)
204212 rest >>= (return . vcat)
205213 first' <- blockToMan opts first
206− return $ first' $$ text "\n.RS" $$ rest' $$ text "\n.RE"
207− return $ text "\n.TP\n.B " <> labelText $+$ contents
214+ return $ first' $$ text ".RS" $$ rest' $$ text ".RE"
215+ return $ text ".TP\n.B " <> labelText $+$ contents
208216
209217-- | Convert list of Pandoc block elements to man.
210218blockListToMan :: WriterOptions -- ^ Options
@@ -240,7 +248,7 @@ inlineToMan opts (Code str) =
240248inlineToMan opts (Str str) = return $ text $ escapeString str
241249inlineToMan opts (TeX str) = return $ text $ escapeCode str
242250inlineToMan 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"
244252inlineToMan opts Space = return $ char ' '
245253inlineToMan opts (Link txt (src, _)) = do
246254 linktext <- inlineListToMan opts txt