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.
This commit is contained in:
John MacFarlane 2010-07-14 10:52:06 -07:00
parent 1436437683
commit 8757da76b0
2 changed files with 81 additions and 55 deletions

View file

@ -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

View file

@ -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)
.IP
.nf
\f[C]
----\ (should\ be\ four\ hyphens)
sub\ status\ {
\ \ \ \ print\ "working";
}
sub\ status\ {
\ \ \ \ print\ "working";
}
this\ code\ block\ is\ indented\ by\ one\ tab
this\ code\ block\ is\ indented\ by\ one\ tab
\f[]
.fi
.PP
And:
.PP
\f[CR]
\ \ \ \ this\ code\ block\ is\ indented\ by\ two\ tabs
.IP
.nf
\f[C]
\ \ \ \ this\ code\ block\ is\ indented\ by\ two\ tabs
These\ should\ not\ be\ escaped:\ \ \\$\ \\\\\ \\>\ \\[\ \\{
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]
<div>
\ \ \ \ foo
</div>
.IP
.nf
\f[C]
<div>
\ \ \ \ foo
</div>
\f[]
.fi
.PP
As should this:
.PP
\f[CR]
<div>foo</div>
.IP
.nf
\f[C]
<div>foo</div>
\f[]
.fi
.PP
Now, nested:
foo
@ -474,18 +486,22 @@ This should just be an HTML comment:
Multiline:
.PP
Code block:
.PP
\f[CR]
<!--\ Comment\ -->
.IP
.nf
\f[C]
<!--\ Comment\ -->
\f[]
.fi
.PP
Just plain comment, with trailing spaces on the line:
.PP
Code:
.PP
\f[CR]
<hr\ />
.IP
.nf
\f[C]
<hr\ />
\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]<html>\f[].
This is code: \f[C]>\f[], \f[C]$\f[], \f[C]\\\f[], \f[C]\\$\f[],
\f[C]<html>\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: <nobody@nowhere.net>
Blockquoted: <http://example.com/>
.RE
.PP
Auto-links should not occur here: \f[B]<http://example.com/>\f[]
.PP
\f[CR]
or\ here:\ <http://example.com/>
Auto-links should not occur here: \f[C]<http://example.com/>\f[]
.IP
.nf
\f[C]
or\ here:\ <http://example.com/>
\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]
\ \ {\ <code>\ }
.IP
.nf
\f[C]
\ \ {\ <code>\ }
\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]