aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJohn MacFarlane <[email protected]>2025-01-14 09:21:16 -0800
committerJohn MacFarlane <[email protected]>2025-01-14 09:27:02 -0800
commit2b6554c475e6e6e500b8cbb39c90b28cc122c423 (patch)
tree022089bfb3fd2cb3247717a91b4ea2e82579c244 /src
parent0a2e8dd1d648df460e3dcb7361f1dc09b4ad3551 (diff)
Fix escaping of `-` in ms writer.
In 5132f1ef330d3eb2a0bf87037035beaeaf19d3f3 we added `-` to the list of characters needing backslash escaping, to accommodate a change in groff man's behavior, described here: https://lwn.net/Articles/947941/ This change also led `-` to be escaped in ms output, but that is wrong; `\-` in ms is a unicode minus sign. To fix this, we add a Boolean parameter to `escapeString` in Text.Pandoc.Writers.Roff that determines whether `-` is to be escaped. (NB: This is not an exported function in the API.) The list `standardEscapes` in Text.Pandoc.RoffChar no longer contains `-`. Closes #10536.
Diffstat (limited to 'src')
-rw-r--r--src/Text/Pandoc/RoffChar.hs1
-rw-r--r--src/Text/Pandoc/Writers/Man.hs6
-rw-r--r--src/Text/Pandoc/Writers/Ms.hs2
-rw-r--r--src/Text/Pandoc/Writers/Roff.hs11
4 files changed, 12 insertions, 8 deletions
diff --git a/src/Text/Pandoc/RoffChar.hs b/src/Text/Pandoc/RoffChar.hs
index feeca2ca3..f5a4134a1 100644
--- a/src/Text/Pandoc/RoffChar.hs
+++ b/src/Text/Pandoc/RoffChar.hs
@@ -34,7 +34,6 @@ standardEscapes =
, ('`', "\\[ga]")
, ('^', "\\[ha]")
, ('~', "\\[ti]")
- , ('-', "\\-")
, ('\\', "\\[rs]")
, ('@', "\\[at]") -- because we use @ as a table and math delimiter
, ('\x2026', "\\&...") -- because u2026 doesn't render on tty
diff --git a/src/Text/Pandoc/Writers/Man.hs b/src/Text/Pandoc/Writers/Man.hs
index 3adf15043..e43caa6e4 100644
--- a/src/Text/Pandoc/Writers/Man.hs
+++ b/src/Text/Pandoc/Writers/Man.hs
@@ -86,9 +86,9 @@ pandocToMan opts (Pandoc meta blocks) = do
Just tpl -> renderTemplate tpl context
escString :: WriterOptions -> Text -> Text
-escString opts = escapeString (if writerPreferAscii opts
- then AsciiOnly
- else AllowUTF8)
+escString opts = escapeString True (if writerPreferAscii opts
+ then AsciiOnly
+ else AllowUTF8)
-- | Return man representation of notes.
notesToMan :: PandocMonad m => WriterOptions -> [[Block]] -> StateT WriterState m (Doc Text)
diff --git a/src/Text/Pandoc/Writers/Ms.hs b/src/Text/Pandoc/Writers/Ms.hs
index dc7fb91fe..e2c97044f 100644
--- a/src/Text/Pandoc/Writers/Ms.hs
+++ b/src/Text/Pandoc/Writers/Ms.hs
@@ -92,7 +92,7 @@ pandocToMs opts (Pandoc meta blocks) = do
escapeStr :: WriterOptions -> Text -> Text
escapeStr opts =
- escapeString (if writerPreferAscii opts then AsciiOnly else AllowUTF8)
+ escapeString False (if writerPreferAscii opts then AsciiOnly else AllowUTF8)
-- In PDFs we need to escape parentheses and backslash.
-- In PDF we need to encode as UTF-16 BE.
diff --git a/src/Text/Pandoc/Writers/Roff.hs b/src/Text/Pandoc/Writers/Roff.hs
index 989c02826..9a891b7a1 100644
--- a/src/Text/Pandoc/Writers/Roff.hs
+++ b/src/Text/Pandoc/Writers/Roff.hs
@@ -74,13 +74,18 @@ combiningAccentsMap = Map.fromList combiningAccents
essentialEscapes :: Map.Map Char Text
essentialEscapes = Map.fromList standardEscapes
--- | Escape special characters for roff.
-escapeString :: EscapeMode -> Text -> Text
-escapeString e = Text.concat . escapeString' e . Text.unpack
+-- | Escape special characters for roff. If the first parameter is
+-- True, escape @-@ as @\-@, as required by current versions of groff man;
+-- otherwise leave it unescaped, as neededfor ms.
+escapeString :: Bool -> EscapeMode -> Text -> Text
+escapeString escapeHyphen e = Text.concat . escapeString' e . Text.unpack
where
escapeString' _ [] = []
escapeString' escapeMode ('\n':'.':xs) =
"\n\\&." : escapeString' escapeMode xs
+ -- see #10533; we need to escape hyphens as \- in man but not in ms:
+ escapeString' escapeMode ('-':xs) | escapeHyphen =
+ "\\-" : escapeString' escapeMode xs
escapeString' escapeMode (x:xs) =
case Map.lookup x essentialEscapes of
Just s -> s : escapeString' escapeMode xs