summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn MacFarlane <jgm@berkeley.edu>2023-08-25 21:35:47 -0700
committerJohn MacFarlane <jgm@berkeley.edu>2023-08-25 21:35:47 -0700
commita6fe02f46a93c8cfaad1a4cb3c5e166a7aea3a4b (patch)
tree7bcbeeeac8e6a4409f9a2e6eaa3c7eacc607d49b
parent0a298cb1bef39d9aa7d756b54aa360e43989431f (diff)
Man writer: improvements to code and code blocks.
The aim here (see #9020) is to produce more standard and more portable man pages. To that end: - We revert the fanciness introduced in #7506, which employs a custom font name V and a macro that makes this act like boldface in a terminal and monospace in other formats. Unfortunately, this code uses a mechanism that is not portable (and does not work in mandoc). - Instead of using V for inline code, we simply use CR. Note that `\f[CR]` is emitted instead of plain `\f[C]`, because there is no C font in man. (This produces warnings in recent versions of groff.) - For code blocks, we now use the `.EX` and `.EE` macros, together with `.IP` for spacing and indentation. This gives more standard code that can be better interpreted e.g. by mandoc.
-rw-r--r--data/templates/default.man14
-rw-r--r--src/Text/Pandoc/Writers/Man.hs9
-rw-r--r--src/Text/Pandoc/Writers/Roff.hs8
-rw-r--r--test/command/3568.md4
-rw-r--r--test/command/5620.md4
-rw-r--r--test/writer.man94
-rw-r--r--test/writer.ms14
7 files changed, 48 insertions, 99 deletions
diff --git a/data/templates/default.man b/data/templates/default.man
index 342a09e4d..84aa37d73 100644
--- a/data/templates/default.man
+++ b/data/templates/default.man
@@ -5,20 +5,6 @@ $if(pandoc-version)$
.\" Automatically generated by Pandoc $pandoc-version$
.\"
$endif$
-.\" Define V font for inline verbatim, using C font in formats
-.\" that render this, and otherwise B font.
-.ie "\f[CB]x\f[]"x" \{\
-. ftr V B
-. ftr VI BI
-. ftr VB B
-. ftr VBI BI
-.\}
-.el \{\
-. ftr V CR
-. ftr VI CI
-. ftr VB CB
-. ftr VBI CBI
-.\}
$if(adjusting)$
.ad $adjusting$
$endif$
diff --git a/src/Text/Pandoc/Writers/Man.hs b/src/Text/Pandoc/Writers/Man.hs
index 794c5518a..fb05df1f7 100644
--- a/src/Text/Pandoc/Writers/Man.hs
+++ b/src/Text/Pandoc/Writers/Man.hs
@@ -131,14 +131,12 @@ blockToMan opts (Header level _ inlines) = do
return $ nowrap $ literal heading <> contents
blockToMan opts (CodeBlock _ str) = return $
literal ".IP" $$
- literal ".nf" $$
- literal "\\f[C]" $$
+ literal ".EX" $$
((case T.uncons str of
Just ('.',_) -> literal "\\&"
_ -> mempty) <>
literal (escString opts str)) $$
- literal "\\f[R]" $$
- literal ".fi"
+ literal ".EE"
blockToMan opts (BlockQuote blocks) = do
contents <- blockListToMan opts blocks
return $ literal ".RS" $$ contents $$ literal ".RE"
@@ -291,8 +289,7 @@ inlineToMan opts (Quoted DoubleQuote lst) = do
inlineToMan opts (Cite _ lst) =
inlineListToMan opts lst
inlineToMan opts (Code _ str) =
- -- note that the V font is specially defined in the default man template
- withFontFeature 'V' (return (literal $ escString opts str))
+ withFontFeature 'C' (return (literal $ escString opts str))
inlineToMan opts (Str str@(T.uncons -> Just ('.',_))) =
return $ afterBreak "\\&" <> literal (escString opts str)
inlineToMan opts (Str str) = return $ literal $ escString opts str
diff --git a/src/Text/Pandoc/Writers/Roff.hs b/src/Text/Pandoc/Writers/Roff.hs
index d5602ebfb..7214e32f0 100644
--- a/src/Text/Pandoc/Writers/Roff.hs
+++ b/src/Text/Pandoc/Writers/Roff.hs
@@ -112,9 +112,11 @@ fontChange = do
fromMaybe False (Map.lookup 'B' features)] ++
['I' | fromMaybe False $ Map.lookup 'I' features]
return $
- if null filling
- then text "\\f[R]"
- else text $ "\\f[" ++ filling ++ "]"
+ case filling of
+ [] -> text "\\f[R]"
+ -- see #9020. C is not a font, use CR.
+ ['C'] -> text "\\f[CR]"
+ _ -> text $ "\\f[" ++ filling ++ "]"
withFontFeature :: (HasChars a, IsString a, PandocMonad m)
=> Char -> MS m (Doc a) -> MS m (Doc a)
diff --git a/test/command/3568.md b/test/command/3568.md
index a6817f4c6..ffc1daada 100644
--- a/test/command/3568.md
+++ b/test/command/3568.md
@@ -10,7 +10,7 @@ normal `code` normal.
normal \f[I]italic \f[BI]bold in the middle\f[I] only italic\f[R]
normal.
.PP
-normal \f[B]bold \f[VB]code\f[B] more bold\f[R] normal.
+normal \f[B]bold \f[CB]code\f[B] more bold\f[R] normal.
.PP
-normal \f[V]code\f[R] normal.
+normal \f[CR]code\f[R] normal.
```
diff --git a/test/command/5620.md b/test/command/5620.md
index cb2635bf0..371a64864 100644
--- a/test/command/5620.md
+++ b/test/command/5620.md
@@ -4,6 +4,6 @@
: Write output to *OUTFILE* instead of `stdout`(3)
^D
.TP
-\f[V]-o\f[R], \f[V]--output=\f[R]\f[I]OUTFILE\f[R]
-Write output to \f[I]OUTFILE\f[R] instead of \f[V]stdout\f[R](3)
+\f[CR]-o\f[R], \f[CR]--output=\f[R]\f[I]OUTFILE\f[R]
+Write output to \f[I]OUTFILE\f[R] instead of \f[CR]stdout\f[R](3)
```
diff --git a/test/writer.man b/test/writer.man
index 5b53a0291..126bf3501 100644
--- a/test/writer.man
+++ b/test/writer.man
@@ -1,17 +1,3 @@
-.\" Define V font for inline verbatim, using C font in formats
-.\" that render this, and otherwise B font.
-.ie "\f[CB]x\f[]"x" \{\
-. ftr V B
-. ftr VI BI
-. ftr VB B
-. ftr VBI BI
-.\}
-.el \{\
-. ftr V CR
-. ftr VI CI
-. ftr VB CB
-. ftr VBI CBI
-.\}
.TH "Pandoc Test Suite" "" "July 17, 2006" "" ""
.PP
This is a set of tests for pandoc.
@@ -65,13 +51,11 @@ It is pretty short.
.PP
Code in a block quote:
.IP
-.nf
-\f[C]
+.EX
sub status {
print \[dq]working\[dq];
}
-\f[R]
-.fi
+.EE
.PP
A list:
.IP "1." 3
@@ -99,8 +83,7 @@ And a following paragraph.
.PP
Code:
.IP
-.nf
-\f[C]
+.EX
---- (should be four hyphens)
sub status {
@@ -108,18 +91,15 @@ sub status {
}
this code block is indented by one tab
-\f[R]
-.fi
+.EE
.PP
And:
.IP
-.nf
-\f[C]
+.EX
this code block is indented by two tabs
These should not be escaped: \[rs]$ \[rs]\[rs] \[rs]> \[rs][ \[rs]{
-\f[R]
-.fi
+.EE
.PP
* * * * *
.SH Lists
@@ -375,11 +355,9 @@ contains seeds, crisp, pleasant to taste
orange fruit
.RS
.IP
-.nf
-\f[C]
+.EX
{ orange code block }
-\f[R]
-.fi
+.EE
.RS
.PP
orange block quote
@@ -440,21 +418,17 @@ foo
.PP
This should be a code block, though:
.IP
-.nf
-\f[C]
+.EX
<div>
foo
</div>
-\f[R]
-.fi
+.EE
.PP
As should this:
.IP
-.nf
-\f[C]
+.EX
<div>foo</div>
-\f[R]
-.fi
+.EE
.PP
Now, nested:
foo
@@ -465,21 +439,17 @@ Multiline:
.PP
Code block:
.IP
-.nf
-\f[C]
+.EX
<!-- Comment -->
-\f[R]
-.fi
+.EE
.PP
Just plain comment, with trailing spaces on the line:
.PP
Code:
.IP
-.nf
-\f[C]
+.EX
<hr />
-\f[R]
-.fi
+.EE
.PP
Hr\[cq]s:
.PP
@@ -500,8 +470,8 @@ So is \f[B]\f[BI]this\f[B]\f[R] word.
.PP
So is \f[B]\f[BI]this\f[B]\f[R] word.
.PP
-This is code: \f[V]>\f[R], \f[V]$\f[R], \f[V]\[rs]\f[R], \f[V]\[rs]$\f[R],
-\f[V]<html>\f[R].
+This is code: \f[CR]>\f[R], \f[CR]$\f[R], \f[CR]\[rs]\f[R], \f[CR]\[rs]$\f[R],
+\f[CR]<html>\f[R].
.PP
[STRIKEOUT:This is \f[I]strikeout\f[R].]
.PP
@@ -525,7 +495,7 @@ So is `pine.'
.PP
`He said, \[lq]I want to go.\[rq]' Were you alive in the 70\[cq]s?
.PP
-Here is some quoted `\f[V]code\f[R]' and a \[lq]quoted
+Here is some quoted `\f[CR]code\f[R]' 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.
@@ -558,7 +528,7 @@ Here\[cq]s one that has a line break in it:
.PP
These shouldn\[cq]t be math:
.IP \[bu] 2
-To get the famous equation, write \f[V]$e = mc\[ha]2$\f[R].
+To get the famous equation, write \f[CR]$e = mc\[ha]2$\f[R].
.IP \[bu] 2
$22,000 is a \f[I]lot\f[R] of money.
So is $34,000.
@@ -566,7 +536,7 @@ So is $34,000.
.IP \[bu] 2
Shoes ($20) and socks ($5).
.IP \[bu] 2
-Escaped \f[V]$\f[R]: $73 \f[I]this should be emphasized\f[R] 23$.
+Escaped \f[CR]$\f[R]: $73 \f[I]this should be emphasized\f[R] 23$.
.PP
Here\[cq]s a LaTeX table:
.PP
@@ -664,11 +634,9 @@ Indented thrice.
.PP
This should [not][] be a link.
.IP
-.nf
-\f[C]
+.EX
[not]: /url
-\f[R]
-.fi
+.EE
.PP
Foo bar.
.PP
@@ -699,13 +667,11 @@ An e-mail address: <nobody@nowhere.net>
Blockquoted: <http://example.com/>
.RE
.PP
-Auto-links should not occur here: \f[V]<http://example.com/>\f[R]
+Auto-links should not occur here: \f[CR]<http://example.com/>\f[R]
.IP
-.nf
-\f[C]
+.EX
or here: <http://example.com/>
-\f[R]
-.fi
+.EE
.PP
* * * * *
.SH Images
@@ -744,18 +710,16 @@ This one contains multiple blocks.
Subsequent blocks are indented to show that they belong to the footnote (as with
list items).
.IP
-.nf
-\f[C]
+.EX
{ <code> }
-\f[R]
-.fi
+.EE
.PP
If you want, you can indent every line, but you can also be lazy and just indent
the first line of each block.
.SS [3]
.PP
This is \f[I]easier\f[R] to type.
-Inline notes may contain links (http://google.com) and \f[V]]\f[R] verbatim
+Inline notes may contain links (http://google.com) and \f[CR]]\f[R] verbatim
characters, as well as [bracketed text].
.SS [4]
.PP
diff --git a/test/writer.ms b/test/writer.ms
index 32d7c1670..4b9b4d251 100644
--- a/test/writer.ms
+++ b/test/writer.ms
@@ -644,8 +644,8 @@ So is \f[B]\f[BI]this\f[B]\f[R] word.
.PP
So is \f[B]\f[BI]this\f[B]\f[R] word.
.PP
-This is code: \f[C]>\f[R], \f[C]$\f[R], \f[C]\[rs]\f[R], \f[C]\[rs]$\f[R],
-\f[C]<html>\f[R].
+This is code: \f[CR]>\f[R], \f[CR]$\f[R], \f[CR]\[rs]\f[R], \f[CR]\[rs]$\f[R],
+\f[CR]<html>\f[R].
.PP
\m[strikecolor]This is \f[I]strikeout\f[R].\m[]
.PP
@@ -671,7 +671,7 @@ So is `pine.'
.PP
`He said, \[lq]I want to go.\[rq]' Were you alive in the 70\[cq]s?
.PP
-Here is some quoted `\f[C]code\f[R]' and a \[lq]\c
+Here is some quoted `\f[CR]code\f[R]' and a \[lq]\c
.pdfhref W -D "http://example.com/?foo=1&bar=2" -A "\c" \
-- "quoted link"
\&\[rq].
@@ -707,7 +707,7 @@ Here\[cq]s one that has a line break in it: @alpha + omega times x sup 2@.
.LP
These shouldn\[cq]t be math:
.IP \[bu] 3
-To get the famous equation, write \f[C]$e = mc\[ha]2$\f[R].
+To get the famous equation, write \f[CR]$e = mc\[ha]2$\f[R].
.IP \[bu] 3
$22,000 is a \f[I]lot\f[R] of money.
So is $34,000.
@@ -715,7 +715,7 @@ So is $34,000.
.IP \[bu] 3
Shoes ($20) and socks ($5).
.IP \[bu] 3
-Escaped \f[C]$\f[R]: $73 \f[I]this should be emphasized\f[R] 23$.
+Escaped \f[CR]$\f[R]: $73 \f[I]this should be emphasized\f[R] 23$.
.LP
Here\[cq]s a LaTeX table:
.HLINE
@@ -938,7 +938,7 @@ Blockquoted: \c
\&
.QE
.LP
-Auto-links should not occur here: \f[C]<http://example.com/>\f[R]
+Auto-links should not occur here: \f[CR]<http://example.com/>\f[R]
.IP
.nf
\f[C]
@@ -991,7 +991,7 @@ This is \f[I]easier\f[R] to type.
Inline notes may contain \c
.pdfhref W -D "http://google.com" -A "\c" \
-- "links"
-\& and \f[C]]\f[R] verbatim characters, as well as [bracketed text].
+\& and \f[CR]]\f[R] verbatim characters, as well as [bracketed text].
.FE
.QS
.LP