aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn MacFarlane <[email protected]>2025-03-29 19:30:04 -0700
committerJohn MacFarlane <[email protected]>2025-03-29 19:30:04 -0700
commit5de83a4cc53e6f11b375c498cc827996f42142e0 (patch)
treefbbbaf14c93a71ab1463bd7dcc694ae79069a356
parent64cde1a03814680da329dc0800a6adbf9980b8cc (diff)
Add `groff` extension affecting `ms` writer.
When this extension is enabled, the `ms` writer won't escape `.pdfhref O` macros in the way that is required when `pdfroff` is used (octal-encoded UTF-16). The extension is not enabled by default. Text.Pandoc.Extensions: add `Ext_groff` constructor [API change].
-rw-r--r--src/Text/Pandoc/Extensions.hs2
-rw-r--r--src/Text/Pandoc/Writers/Ms.hs5
2 files changed, 6 insertions, 1 deletions
diff --git a/src/Text/Pandoc/Extensions.hs b/src/Text/Pandoc/Extensions.hs
index 7f1b35c17..cc1afd26c 100644
--- a/src/Text/Pandoc/Extensions.hs
+++ b/src/Text/Pandoc/Extensions.hs
@@ -144,6 +144,7 @@ data Extension =
| Ext_xrefs_name -- ^ Use xrefs with names
| Ext_xrefs_number -- ^ Use xrefs with numbers
| Ext_yaml_metadata_block -- ^ YAML metadata block
+ | Ext_groff -- ^ Use groff form for .pdfhref macro in ms
| CustomExtension T.Text -- ^ Custom extension
deriving (Show, Read, Eq, Ord, Data, Typeable, Generic)
@@ -659,4 +660,5 @@ getAllExtensions f = universalExtensions <> getAll f
[ Ext_smart ]
getAll "typst" = extensionsFromList [Ext_citations, Ext_smart]
getAll "djot" = extensionsFromList [Ext_sourcepos]
+ getAll "ms" = extensionsFromList [Ext_groff]
getAll _ = mempty
diff --git a/src/Text/Pandoc/Writers/Ms.hs b/src/Text/Pandoc/Writers/Ms.hs
index ba14f9a55..33dc658c5 100644
--- a/src/Text/Pandoc/Writers/Ms.hs
+++ b/src/Text/Pandoc/Writers/Ms.hs
@@ -199,7 +199,10 @@ blockToMs opts (Header level (ident,classes,_) inlines) = do
(if T.null secnum
then ""
else " ") <>
- escapePDFString plainContents)
+ (if isEnabled Ext_groff opts
+ then id
+ else escapePDFString)
+ plainContents)
let backlink = nowrap (literal ".pdfhref L -D " <>
doubleQuotes (literal (toAscii ident)) <> space <> literal "\\") <> cr <>
literal " -- "