aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJohn MacFarlane <[email protected]>2023-08-25 21:35:47 -0700
committerJohn MacFarlane <[email protected]>2023-08-25 21:35:47 -0700
commita6fe02f46a93c8cfaad1a4cb3c5e166a7aea3a4b (patch)
tree7bcbeeeac8e6a4409f9a2e6eaa3c7eacc607d49b /src
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.
Diffstat (limited to 'src')
-rw-r--r--src/Text/Pandoc/Writers/Man.hs9
-rw-r--r--src/Text/Pandoc/Writers/Roff.hs8
2 files changed, 8 insertions, 9 deletions
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)