Skip to content

Commit 2b6554c

Browse files
committed
Fix escaping of - in ms writer.
In 5132f1e 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.
1 parent 0a2e8dd commit 2b6554c

File tree

5 files changed

+21
-17
lines changed

5 files changed

+21
-17
lines changed

src/Text/Pandoc/RoffChar.hs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ standardEscapes =
3434
, ('`', "\\[ga]")
3535
, ('^', "\\[ha]")
3636
, ('~', "\\[ti]")
37-
, ('-', "\\-")
3837
, ('\\', "\\[rs]")
3938
, ('@', "\\[at]") -- because we use @ as a table and math delimiter
4039
, ('\x2026', "\\&...") -- because u2026 doesn't render on tty

src/Text/Pandoc/Writers/Man.hs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,9 +86,9 @@ pandocToMan opts (Pandoc meta blocks) = do
8686
Just tpl -> renderTemplate tpl context
8787

8888
escString :: WriterOptions -> Text -> Text
89-
escString opts = escapeString (if writerPreferAscii opts
90-
then AsciiOnly
91-
else AllowUTF8)
89+
escString opts = escapeString True (if writerPreferAscii opts
90+
then AsciiOnly
91+
else AllowUTF8)
9292

9393
-- | Return man representation of notes.
9494
notesToMan :: PandocMonad m => WriterOptions -> [[Block]] -> StateT WriterState m (Doc Text)

src/Text/Pandoc/Writers/Ms.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ pandocToMs opts (Pandoc meta blocks) = do
9292

9393
escapeStr :: WriterOptions -> Text -> Text
9494
escapeStr opts =
95-
escapeString (if writerPreferAscii opts then AsciiOnly else AllowUTF8)
95+
escapeString False (if writerPreferAscii opts then AsciiOnly else AllowUTF8)
9696

9797
-- In PDFs we need to escape parentheses and backslash.
9898
-- In PDF we need to encode as UTF-16 BE.

src/Text/Pandoc/Writers/Roff.hs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,13 +74,18 @@ combiningAccentsMap = Map.fromList combiningAccents
7474
essentialEscapes :: Map.Map Char Text
7575
essentialEscapes = Map.fromList standardEscapes
7676

77-
-- | Escape special characters for roff.
78-
escapeString :: EscapeMode -> Text -> Text
79-
escapeString e = Text.concat . escapeString' e . Text.unpack
77+
-- | Escape special characters for roff. If the first parameter is
78+
-- True, escape @-@ as @\-@, as required by current versions of groff man;
79+
-- otherwise leave it unescaped, as neededfor ms.
80+
escapeString :: Bool -> EscapeMode -> Text -> Text
81+
escapeString escapeHyphen e = Text.concat . escapeString' e . Text.unpack
8082
where
8183
escapeString' _ [] = []
8284
escapeString' escapeMode ('\n':'.':xs) =
8385
"\n\\&." : escapeString' escapeMode xs
86+
-- see #10533; we need to escape hyphens as \- in man but not in ms:
87+
escapeString' escapeMode ('-':xs) | escapeHyphen =
88+
"\\-" : escapeString' escapeMode xs
8489
escapeString' escapeMode (x:xs) =
8590
case Map.lookup x essentialEscapes of
8691
Just s -> s : escapeString' escapeMode xs

test/writer.ms

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ Here\[cq]s a regular paragraph.
134134
In Markdown 1.0.0 and earlier.
135135
Version 8.
136136
This line turns into a list item.
137-
Because a hard\-wrapped line in the middle of a paragraph looked like a list
137+
Because a hard-wrapped line in the middle of a paragraph looked like a list
138138
item.
139139
.PP
140140
Here\[cq]s one with a bullet.
@@ -149,7 +149,7 @@ Block Quotes
149149
.pdfhref O 1 "Block Quotes"
150150
.pdfhref M "block-quotes"
151151
.LP
152-
E\-mail style:
152+
E-mail style:
153153
.QS
154154
.LP
155155
This is a block quote.
@@ -197,7 +197,7 @@ Code:
197197
.IP
198198
.nf
199199
\f[C]
200-
\-\-\-\- (should be four hyphens)
200+
---- (should be four hyphens)
201201

202202
sub status {
203203
print \[dq]working\[dq];
@@ -605,7 +605,7 @@ Code block:
605605
.IP
606606
.nf
607607
\f[C]
608-
<!\-\- Comment \-\->
608+
<!-- Comment -->
609609
\f[]
610610
.fi
611611
.LP
@@ -695,7 +695,7 @@ LaTeX
695695
.IP \[bu] 3
696696
@223@
697697
.IP \[bu] 3
698-
@p@\-Tree
698+
@p@-Tree
699699
.IP \[bu] 3
700700
Here\[cq]s some display math:
701701
.EQ
@@ -765,7 +765,7 @@ Left paren: (
765765
.PP
766766
Right paren: )
767767
.PP
768-
Greater\-than: >
768+
Greater-than: >
769769
.PP
770770
Hash: #
771771
.PP
@@ -775,7 +775,7 @@ Bang: !
775775
.PP
776776
Plus: +
777777
.PP
778-
Minus: \-
778+
Minus: -
779779
.HLINE
780780
.SH 1
781781
Links
@@ -925,7 +925,7 @@ In a list?
925925
.IP \[bu] 3
926926
It should.
927927
.LP
928-
An e\-mail address: \c
928+
An e-mail address: \c
929929
.pdfhref W -D "mailto:nobody%40nowhere.net" -A "\c" \
930930
-- "nobody\[at]nowhere.net"
931931
\&
@@ -937,7 +937,7 @@ Blockquoted: \c
937937
\&
938938
.QE
939939
.LP
940-
Auto\-links should not occur here: \f[CR]<http://example.com/>\f[R]
940+
Auto-links should not occur here: \f[CR]<http://example.com/>\f[R]
941941
.IP
942942
.nf
943943
\f[C]

0 commit comments

Comments
 (0)