From 8757da76b0e4c26f722ac4742689739b2b5dfb08 Mon Sep 17 00:00:00 2001 From: John MacFarlane Date: Wed, 14 Jul 2010 10:52:06 -0700 Subject: Improved handling of code in man writer. + Inline code is now in monoscpace, not bold. + Code blocks now use .nf (no fill) and .IP (indented paragraph). + Resolves Issue #247. --- src/Text/Pandoc/Writers/Man.hs | 10 +++- tests/writer.man | 126 ++++++++++++++++++++++++----------------- 2 files changed, 81 insertions(+), 55 deletions(-) diff --git a/src/Text/Pandoc/Writers/Man.hs b/src/Text/Pandoc/Writers/Man.hs index c74cd81f9..45e7e5083 100644 --- a/src/Text/Pandoc/Writers/Man.hs +++ b/src/Text/Pandoc/Writers/Man.hs @@ -151,8 +151,12 @@ blockToMan opts (Header level inlines) = do _ -> ".SS " return $ text heading <> contents blockToMan _ (CodeBlock _ str) = return $ - text ".PP" $$ text "\\f[CR]" $$ - text ((unlines . map (" " ++) . lines) (escapeCode str)) <> text "\\f[]" + text ".IP" $$ + text ".nf" $$ + text "\\f[C]" $$ + text (escapeCode str) $$ + text "\\f[]" $$ + text ".fi" blockToMan opts (BlockQuote blocks) = do contents <- blockListToMan opts blocks return $ text ".RS" $$ contents $$ text ".RE" @@ -300,7 +304,7 @@ inlineToMan _ EnDash = return $ text "\\[en]" inlineToMan _ Apostrophe = return $ char '\'' inlineToMan _ Ellipses = return $ text "\\&..." inlineToMan _ (Code str) = - return $ text $ "\\f[B]" ++ escapeCode str ++ "\\f[]" + return $ text $ "\\f[C]" ++ escapeCode str ++ "\\f[]" inlineToMan _ (Str str) = return $ text $ escapeString str inlineToMan opts (Math InlineMath str) = inlineListToMan opts $ readTeXMath str inlineToMan opts (Math DisplayMath str) = do diff --git a/tests/writer.man b/tests/writer.man index e9d950bc4..c0b2aa8b6 100644 --- a/tests/writer.man +++ b/tests/writer.man @@ -50,12 +50,14 @@ It is pretty short. .RS .PP Code in a block quote: -.PP -\f[CR] - sub\ status\ { - \ \ \ \ print\ "working"; - } +.IP +.nf +\f[C] +sub\ status\ { +\ \ \ \ print\ "working"; +} \f[] +.fi .PP A list: .IP "1." 3 @@ -82,24 +84,28 @@ And a following paragraph. .SH Code Blocks .PP Code: -.PP -\f[CR] - ----\ (should\ be\ four\ hyphens) - - sub\ status\ { - \ \ \ \ print\ "working"; - } - - this\ code\ block\ is\ indented\ by\ one\ tab +.IP +.nf +\f[C] +----\ (should\ be\ four\ hyphens) + +sub\ status\ { +\ \ \ \ print\ "working"; +} + +this\ code\ block\ is\ indented\ by\ one\ tab \f[] +.fi .PP And: -.PP -\f[CR] - \ \ \ \ this\ code\ block\ is\ indented\ by\ two\ tabs - - These\ should\ not\ be\ escaped:\ \ \\$\ \\\\\ \\>\ \\[\ \\{ +.IP +.nf +\f[C] +\ \ \ \ this\ code\ block\ is\ indented\ by\ two\ tabs + +These\ should\ not\ be\ escaped:\ \ \\$\ \\\\\ \\>\ \\[\ \\{ \f[] +.fi .PP * * * * * .SH Lists @@ -372,10 +378,12 @@ contains seeds, crisp, pleasant to taste .B \f[I]orange\f[] orange fruit .RS -.PP -\f[CR] - {\ orange\ code\ block\ } +.IP +.nf +\f[C] +{\ orange\ code\ block\ } \f[] +.fi .RS .PP orange block quote @@ -453,18 +461,22 @@ Here's a simple block: foo .PP This should be a code block, though: -.PP -\f[CR] -
- \ \ \ \ foo -
+.IP +.nf +\f[C] +
+\ \ \ \ foo +
\f[] +.fi .PP As should this: -.PP -\f[CR] -
foo
+.IP +.nf +\f[C] +
foo
\f[] +.fi .PP Now, nested: foo @@ -474,18 +486,22 @@ This should just be an HTML comment: Multiline: .PP Code block: -.PP -\f[CR] - +.IP +.nf +\f[C] + \f[] +.fi .PP Just plain comment, with trailing spaces on the line: .PP Code: -.PP -\f[CR] - +.IP +.nf +\f[C] + \f[] +.fi .PP Hr's: .PP @@ -506,8 +522,8 @@ So is \f[B]\f[I]this\f[]\f[] word. .PP So is \f[B]\f[I]this\f[]\f[] word. .PP -This is code: \f[B]>\f[], \f[B]$\f[], \f[B]\\\f[], \f[B]\\$\f[], -\f[B]\f[]. +This is code: \f[C]>\f[], \f[C]$\f[], \f[C]\\\f[], \f[C]\\$\f[], +\f[C]\f[]. .PP [STRIKEOUT:This is \f[I]strikeout\f[].] .PP @@ -531,7 +547,7 @@ So is `pine.' .PP `He said, \[lq]I want to go.\[rq]' Were you alive in the 70's? .PP -Here is some quoted `\f[B]code\f[]' and a +Here is some quoted `\f[C]code\f[]' and a \[lq]quoted link (http://example.com/?foo=1&bar=2)\[rq]. .PP Some dashes: one\[em]two \[em] three\[em]four \[em] five. @@ -563,7 +579,7 @@ Here's one that has a line break in it: α + ω × \f[I]x\f[]^2^. .PP These shouldn't be math: .IP \[bu] 2 -To get the famous equation, write \f[B]$e\ =\ mc^2$\f[]. +To get the famous equation, write \f[C]$e\ =\ mc^2$\f[]. .IP \[bu] 2 $22,000 is a \f[I]lot\f[] of money. So is $34,000. @@ -571,7 +587,7 @@ So is $34,000. .IP \[bu] 2 Shoes ($20) and socks ($5). .IP \[bu] 2 -Escaped \f[B]$\f[]: $73 \f[I]this should be emphasized\f[] 23$. +Escaped \f[C]$\f[]: $73 \f[I]this should be emphasized\f[] 23$. .PP Here's a LaTeX table: .PP @@ -673,10 +689,12 @@ Indented twice (/url). Indented thrice (/url). .PP This should [not][] be a link. -.PP -\f[CR] - [not]:\ /url +.IP +.nf +\f[C] +[not]:\ /url \f[] +.fi .PP Foo bar (/url/). .PP @@ -708,11 +726,13 @@ An e-mail address: Blockquoted: .RE .PP -Auto-links should not occur here: \f[B]\f[] -.PP -\f[CR] - or\ here:\ +Auto-links should not occur here: \f[C]\f[] +.IP +.nf +\f[C] +or\ here:\ \f[] +.fi .PP * * * * * .SH Images @@ -753,10 +773,12 @@ This one contains multiple blocks. .PP Subsequent blocks are indented to show that they belong to the footnote (as with list items). -.PP -\f[CR] - \ \ {\ \ } +.IP +.nf +\f[C] +\ \ {\ \ } \f[] +.fi .PP If you want, you can indent every line, but you can also be lazy and just indent the first line of each block. @@ -764,7 +786,7 @@ and just indent the first line of each block. .SS [3] .PP This is \f[I]easier\f[] to type. -Inline notes may contain links (http://google.com) and \f[B]]\f[] +Inline notes may contain links (http://google.com) and \f[C]]\f[] verbatim characters, as well as [bracketed text]. .SS [4] -- cgit v1.2.3