@@ -69,6 +69,9 @@ writeMs :: PandocMonad m => WriterOptions -> Pandoc -> m Text
6969writeMs opts document =
7070 evalStateT (pandocToMs opts document) defaultWriterState
7171
72+escString :: WriterOptions -> String -> String
73+escString opts = escapeString (writerPreferAscii opts)
74+
7275-- | Return groff ms representation of document.
7376pandocToMs :: PandocMonad m => WriterOptions -> Pandoc -> MS m Text
7477pandocToMs opts (Pandoc meta blocks) = do
@@ -84,8 +87,8 @@ pandocToMs opts (Pandoc meta blocks) = do
8487 body <- blockListToMs opts blocks
8588 let main = render' body
8689 hasInlineMath <- gets stHasInlineMath
87− let titleMeta = (escapeString . stringify) $ docTitle meta
88− let authorsMeta = map (escapeString . stringify) $ docAuthors meta
90+ let titleMeta = (escString opts . stringify) $ docTitle meta
91+ let authorsMeta = map (escString opts . stringify) $ docAuthors meta
8992 hasHighlighting <- gets stHighlighting
9093 let highlightingMacros = if hasHighlighting
9194 then case writerHighlightStyle opts of
@@ -101,8 +104,7 @@ pandocToMs opts (Pandoc meta blocks) = do
101104 $ defField "title-meta" titleMeta
102105 $ defField "author-meta" (intercalate "; " authorsMeta)
103106 $ defField "highlighting-macros" highlightingMacros metadata
104− (if writerPreferAscii opts then groffEscape else id) <$>
105− case writerTemplate opts of
107+ case writerTemplate opts of
106108 Nothing -> return main
107109 Just tpl -> renderTemplate' tpl context
108110
@@ -112,18 +114,18 @@ escapeUri = escapeURIString (\c -> c /= '@' && isAllowedInURI c)
112114-- | Escape | character, used to mark inline math, inside math.
113115escapeBar :: String -> String
114116escapeBar = concatMap go
115− where go '|' = "\\[u007C]"
117+ where go '|' = "\\[ba]"
116118 go c = [c]
117119
118−toSmallCaps :: String -> String
119−toSmallCaps [] = []
120−toSmallCaps (c:cs)
120+toSmallCaps :: WriterOptions -> String -> String
121+toSmallCaps _ [] = []
122+toSmallCaps opts (c:cs)
121123 | isLower c = let (lowers,rest) = span isLower (c:cs)
122− in "\\s-2" ++ escapeString (map toUpper lowers) ++
123− "\\s0" ++ toSmallCaps rest
124+ in "\\s-2" ++ escString opts (map toUpper lowers) ++
125+ "\\s0" ++ toSmallCaps opts rest
124126 | isUpper c = let (uppers,rest) = span isUpper (c:cs)
125− in escapeString uppers ++ toSmallCaps rest
126− | otherwise = escapeChar c ++ toSmallCaps cs
127+ in escString opts uppers ++ toSmallCaps opts rest
128+ | otherwise = escapeChar (writerPreferAscii opts) c ++ toSmallCaps opts cs
127129
128130-- We split inline lists into sentences, and print one sentence per
129131-- line. groff/troff treats the line-ending period differently.
@@ -160,7 +162,7 @@ blockToMs opts (Para [Image attr alt (src,_tit)])
160162 _ -> empty
161163 capt <- inlineListToMs' opts alt
162164 return $ nowrap (text ".PSPIC -C " <>
163− doubleQuotes (text (escapeString src)) <>
165+ doubleQuotes (text (escString opts src)) <>
164166 sizeAttrs) $$
165167 text ".ce 1000" $$
166168 capt $$
@@ -198,7 +200,7 @@ blockToMs opts (Header level (ident,classes,_) inlines) = do
198200 (if null secnum
199201 then ""
200202 else " ") ++
201− escapeString (stringify inlines))
203+ escString opts (stringify inlines))
202204 let backlink = nowrap (text ".pdfhref L -D " <>
203205 doubleQuotes (text (toAscii ident)) <> space <> text "\\") <> cr <>
204206 text " -- "
@@ -400,14 +402,14 @@ inlineToMs opts (Cite _ lst) =
400402inlineToMs opts (Code attr str) = do
401403 hlCode <- highlightCode opts attr str
402404 withFontFeature 'C' (return hlCode)
403−inlineToMs _ (Str str) = do
405+inlineToMs opts (Str str) = do
404406 let shim = case str of
405407 '.':_ -> afterBreak "\\&"
406408 _ -> empty
407409 smallcaps <- gets stSmallCaps
408410 if smallcaps
409− then return $ shim <> text (toSmallCaps str)
410− else return $ shim <> text (escapeString str)
411+ then return $ shim <> text (toSmallCaps opts str)
412+ else return $ shim <> text (escString opts str)
411413inlineToMs opts (Math InlineMath str) = do
412414 modify $ \st -> st{ stHasInlineMath = True }
413415 res <- convertMath writeEqn InlineMath str
@@ -449,9 +451,10 @@ inlineToMs opts (Link _ txt (src, _)) = do
449451 doubleQuotes (text (escapeUri src)) <> text " -A " <>
450452 doubleQuotes (text "\\c") <> space <> text "\\") <> cr <>
451453 text " -- " <> doubleQuotes (nowrap contents) <> cr <> text "\\&"
452−inlineToMs _ (Image _ alternate (_, _)) =
454+inlineToMs opts (Image _ alternate (_, _)) =
453455 return $ char '[' <> text "IMAGE: " <>
454− text (escapeString (stringify alternate)) <> char ']'
456+ text (escString opts (stringify alternate))
457+ <> char ']'
455458inlineToMs _ (Note contents) = do
456459 modify $ \st -> st{ stNotes = contents : stNotes st }
457460 return $ text "\\**"
@@ -531,20 +534,21 @@ toMacro sty toktype =
531534 -- lnColor = lineNumberColor sty
532535 -- lnBkgColor = lineNumberBackgroundColor sty
533536
534−msFormatter :: FormatOptions -> [SourceLine] -> Doc
535−msFormatter _fmtopts =
537+msFormatter :: WriterOptions -> FormatOptions -> [SourceLine] -> Doc
538+msFormatter opts _fmtopts =
536539 vcat . map fmtLine
537540 where fmtLine = hcat . map fmtToken
538541 fmtToken (toktype, tok) = text "\\*" <>
539542 brackets (text (show toktype) <> text " \""
540− <> text (escapeCode (T.unpack tok)) <> text "\"")
543+ <> text (escapeCode (writerPreferAscii opts)
544+ (T.unpack tok)) <> text "\"")
541545
542546highlightCode :: PandocMonad m => WriterOptions -> Attr -> String -> MS m Doc
543547highlightCode opts attr str =
544− case highlight (writerSyntaxMap opts) msFormatter attr str of
548+ case highlight (writerSyntaxMap opts) (msFormatter opts) attr str of
545549 Left msg -> do
546550 unless (null msg) $ report $ CouldNotHighlight msg
547− return $ text (escapeCode str)
551+ return $ text (escapeCode (writerPreferAscii opts) str)
548552 Right h -> do
549553 modify (\st -> st{ stHighlighting = True })
550554 return h