diff options
| author | John MacFarlane <[email protected]> | 2025-03-23 11:14:37 -0700 |
|---|---|---|
| committer | John MacFarlane <[email protected]> | 2025-03-23 11:14:37 -0700 |
| commit | 752f1981879723f0ec2f749f5fe4e41469cc1e13 (patch) | |
| tree | 19b2989f74e26b5e7e94c46160886d2eed243f29 /src | |
| parent | 3bbca20240ebc26d614a6d01a44ceb39f0d994ec (diff) | |
T.P.Writers.Roff: use the most compatible form.
The form `\[e aa]` works for groff but not for all roff's (not for
macOS man for instance). So instead we'll emit `e` followed by
an escape for a unicode combining accent.
See #10716.
Diffstat (limited to 'src')
| -rw-r--r-- | src/Text/Pandoc/Writers/Roff.hs | 32 |
1 files changed, 11 insertions, 21 deletions
diff --git a/src/Text/Pandoc/Writers/Roff.hs b/src/Text/Pandoc/Writers/Roff.hs index a37b93ee4..c486871fe 100644 --- a/src/Text/Pandoc/Writers/Roff.hs +++ b/src/Text/Pandoc/Writers/Roff.hs @@ -26,13 +26,12 @@ import qualified Data.Map as Map import Data.Text (Text) import qualified Data.Text as Text import Data.String -import Data.Maybe (fromMaybe, isJust, catMaybes) +import Data.Maybe (fromMaybe) import Text.Pandoc.Class.PandocMonad (PandocMonad) import Text.Pandoc.Definition import Text.DocLayout import Text.Printf (printf) -import Text.Pandoc.RoffChar (standardEscapes, - characterCodes, combiningAccents) +import Text.Pandoc.RoffChar (standardEscapes, characterCodes) data WriterState = WriterState { stHasInlineMath :: Bool , stFirstPara :: Bool @@ -68,9 +67,6 @@ data EscapeMode = AllowUTF8 -- ^ use preferred man escapes | AsciiOnly -- ^ escape everything deriving Show -combiningAccentsMap :: Map.Map Char Text -combiningAccentsMap = Map.fromList combiningAccents - essentialEscapes :: Map.Map Char Text essentialEscapes = Map.fromList standardEscapes @@ -92,22 +88,16 @@ escapeString escapeHyphen e = Text.concat . escapeString' e . Text.unpack Nothing | isAscii x -> Text.singleton x : escapeString' escapeMode xs | otherwise -> - case escapeMode of - AllowUTF8 -> Text.singleton x : escapeString' escapeMode xs + (case escapeMode of + AllowUTF8 -> Text.singleton x AsciiOnly -> - let accents = catMaybes $ takeWhile isJust - (map (`Map.lookup` combiningAccentsMap) xs) - rest = drop (length accents) xs - s = case Map.lookup x characterCodeMap of - Just t -> - if null accents - then if Text.length t == 2 - then "\\(" <> t -- see #10716 - else "\\[" <> t <> "]" - else "\\[" <> Text.unwords (t:accents) <> "]" - Nothing -> "\\[" <> Text.unwords - (Text.pack (printf "u%04X" (ord x)) : accents) <> "]" - in s : escapeString' escapeMode rest + case Map.lookup x characterCodeMap of + Just t + | Text.length t == 2 -> "\\(" <> t -- see #10716 + | otherwise -> "\\C'" <> t <> "'" + Nothing -> + "\\C'" <> Text.pack (printf "u%04X" (ord x)) <> "'") + : escapeString' escapeMode xs characterCodeMap :: Map.Map Char Text characterCodeMap = Map.fromList characterCodes |
