@@ -69,6 +69,9 @@ writeMs :: PandocMonad m => WriterOptions -> Pandoc -> m Text
69writeMs opts document =
69writeMs opts document =
70 evalStateT (pandocToMs opts document) defaultWriterState
70 evalStateT (pandocToMs opts document) defaultWriterState
72+escString :: WriterOptions -> String -> String
73+escString opts = escapeString (writerPreferAscii opts)
72-- | Return groff ms representation of document.
75-- | Return groff ms representation of document.
73pandocToMs :: PandocMonad m => WriterOptions -> Pandoc -> MS m Text
76pandocToMs :: PandocMonad m => WriterOptions -> Pandoc -> MS m Text
74pandocToMs opts (Pandoc meta blocks) = do
77pandocToMs opts (Pandoc meta blocks) = do
@@ -84,8 +87,8 @@ pandocToMs opts (Pandoc meta blocks) = do
84 body <- blockListToMs opts blocks
87 body <- blockListToMs opts blocks
85 let main = render' body
88 let main = render' body
86 hasInlineMath <- gets stHasInlineMath
89 hasInlineMath <- gets stHasInlineMath
87− let titleMeta = (escapeString . stringify) $ docTitle meta
90+ let titleMeta = (escString opts . stringify) $ docTitle meta
88− let authorsMeta = map (escapeString . stringify) $ docAuthors meta
91+ let authorsMeta = map (escString opts . stringify) $ docAuthors meta
89 hasHighlighting <- gets stHighlighting
92 hasHighlighting <- gets stHighlighting
90 let highlightingMacros = if hasHighlighting
93 let highlightingMacros = if hasHighlighting
91 then case writerHighlightStyle opts of
94 then case writerHighlightStyle opts of
@@ -101,8 +104,7 @@ pandocToMs opts (Pandoc meta blocks) = do
101 $ defField "title-meta" titleMeta
104 $ defField "title-meta" titleMeta
102 $ defField "author-meta" (intercalate "; " authorsMeta)
105 $ defField "author-meta" (intercalate "; " authorsMeta)
103 $ defField "highlighting-macros" highlightingMacros metadata
106 $ defField "highlighting-macros" highlightingMacros metadata
104− (if writerPreferAscii opts then groffEscape else id) <$>
105− case writerTemplate opts of
107+ case writerTemplate opts of
106 Nothing -> return main
108 Nothing -> return main
107 Just tpl -> renderTemplate' tpl context
109 Just tpl -> renderTemplate' tpl context
@@ -112,18 +114,18 @@ escapeUri = escapeURIString (\c -> c /= '@' && isAllowedInURI c)
112-- | Escape | character, used to mark inline math, inside math.
114-- | Escape | character, used to mark inline math, inside math.
113escapeBar :: String -> String
115escapeBar :: String -> String
114escapeBar = concatMap go
116escapeBar = concatMap go
115− where go '|' = "\\[u007C]"
117+ where go '|' = "\\[ba]"
116 go c = [c]
118 go c = [c]
118−toSmallCaps :: String -> String
120+toSmallCaps :: WriterOptions -> String -> String
119−toSmallCaps [] = []
121+toSmallCaps _ [] = []
120−toSmallCaps (c:cs)
122+toSmallCaps opts (c:cs)
121 | isLower c = let (lowers,rest) = span isLower (c:cs)
123 | isLower c = let (lowers,rest) = span isLower (c:cs)
122− in "\\s-2" ++ escapeString (map toUpper lowers) ++
124+ in "\\s-2" ++ escString opts (map toUpper lowers) ++
123− "\\s0" ++ toSmallCaps rest
125+ "\\s0" ++ toSmallCaps opts rest
124 | isUpper c = let (uppers,rest) = span isUpper (c:cs)
126 | isUpper c = let (uppers,rest) = span isUpper (c:cs)
125− in escapeString uppers ++ toSmallCaps rest
127+ in escString opts uppers ++ toSmallCaps opts rest
126− | otherwise = escapeChar c ++ toSmallCaps cs
128+ | otherwise = escapeChar (writerPreferAscii opts) c ++ toSmallCaps opts cs
128-- We split inline lists into sentences, and print one sentence per
130-- We split inline lists into sentences, and print one sentence per
129-- line. groff/troff treats the line-ending period differently.
131-- line. groff/troff treats the line-ending period differently.
@@ -160,7 +162,7 @@ blockToMs opts (Para [Image attr alt (src,_tit)])
160 _ -> empty
162 _ -> empty
161 capt <- inlineListToMs' opts alt
163 capt <- inlineListToMs' opts alt
162 return $ nowrap (text ".PSPIC -C " <>
164 return $ nowrap (text ".PSPIC -C " <>
163− doubleQuotes (text (escapeString src)) <>
165+ doubleQuotes (text (escString opts src)) <>
164 sizeAttrs) $$
166 sizeAttrs) $$
165 text ".ce 1000" $$
167 text ".ce 1000" $$
@@ -198,7 +200,7 @@ blockToMs opts (Header level (ident,classes,_) inlines) = do
198 (if null secnum
200 (if null secnum
200 else " ") ++
202 else " ") ++
201− escapeString (stringify inlines))
203+ escString opts (stringify inlines))
202 let backlink = nowrap (text ".pdfhref L -D " <>
204 let backlink = nowrap (text ".pdfhref L -D " <>
203 doubleQuotes (text (toAscii ident)) <> space <> text "\\") <> cr <>
205 doubleQuotes (text (toAscii ident)) <> space <> text "\\") <> cr <>
204 text " -- "
206 text " -- "
@@ -400,14 +402,14 @@ inlineToMs opts (Cite _ lst) =
400inlineToMs opts (Code attr str) = do
402inlineToMs opts (Code attr str) = do
401 hlCode <- highlightCode opts attr str
403 hlCode <- highlightCode opts attr str
402 withFontFeature 'C' (return hlCode)
404 withFontFeature 'C' (return hlCode)
403−inlineToMs _ (Str str) = do
405+inlineToMs opts (Str str) = do
404 let shim = case str of
406 let shim = case str of
405 '.':_ -> afterBreak "\\&"
407 '.':_ -> afterBreak "\\&"
406 _ -> empty
408 _ -> empty
407 smallcaps <- gets stSmallCaps
409 smallcaps <- gets stSmallCaps
408 if smallcaps
410 if smallcaps
409− then return $ shim <> text (toSmallCaps str)
411+ then return $ shim <> text (toSmallCaps opts str)
410− else return $ shim <> text (escapeString str)
412+ else return $ shim <> text (escString opts str)
411inlineToMs opts (Math InlineMath str) = do
413inlineToMs opts (Math InlineMath str) = do
412 modify $ \st -> st{ stHasInlineMath = True }
414 modify $ \st -> st{ stHasInlineMath = True }
413 res <- convertMath writeEqn InlineMath str
415 res <- convertMath writeEqn InlineMath str
@@ -449,9 +451,10 @@ inlineToMs opts (Link _ txt (src, _)) = do
449 doubleQuotes (text (escapeUri src)) <> text " -A " <>
451 doubleQuotes (text (escapeUri src)) <> text " -A " <>
450 doubleQuotes (text "\\c") <> space <> text "\\") <> cr <>
452 doubleQuotes (text "\\c") <> space <> text "\\") <> cr <>
451 text " -- " <> doubleQuotes (nowrap contents) <> cr <> text "\\&"
453 text " -- " <> doubleQuotes (nowrap contents) <> cr <> text "\\&"
452−inlineToMs _ (Image _ alternate (_, _)) =
454+inlineToMs opts (Image _ alternate (_, _)) =
453 return $ char '[' <> text "IMAGE: " <>
455 return $ char '[' <> text "IMAGE: " <>
454− text (escapeString (stringify alternate)) <> char ']'
456+ text (escString opts (stringify alternate))
455inlineToMs _ (Note contents) = do
458inlineToMs _ (Note contents) = do
456 modify $ \st -> st{ stNotes = contents : stNotes st }
459 modify $ \st -> st{ stNotes = contents : stNotes st }
457 return $ text "\\**"
460 return $ text "\\**"
@@ -531,20 +534,21 @@ toMacro sty toktype =
531 -- lnColor = lineNumberColor sty
534 -- lnColor = lineNumberColor sty
532 -- lnBkgColor = lineNumberBackgroundColor sty
535 -- lnBkgColor = lineNumberBackgroundColor sty
534−msFormatter :: FormatOptions -> [SourceLine] -> Doc
537+msFormatter :: WriterOptions -> FormatOptions -> [SourceLine] -> Doc
535−msFormatter _fmtopts =
538+msFormatter opts _fmtopts =
536 vcat . map fmtLine
539 vcat . map fmtLine
537 where fmtLine = hcat . map fmtToken
540 where fmtLine = hcat . map fmtToken
538 fmtToken (toktype, tok) = text "\\*" <>
541 fmtToken (toktype, tok) = text "\\*" <>
539 brackets (text (show toktype) <> text " \""
542 brackets (text (show toktype) <> text " \""
543+ <> text (escapeCode (writerPreferAscii opts)
540− <> text (escapeCode (T.unpack tok)) <> text "\"")
544+ (T.unpack tok)) <> text "\"")
542highlightCode :: PandocMonad m => WriterOptions -> Attr -> String -> MS m Doc
546highlightCode :: PandocMonad m => WriterOptions -> Attr -> String -> MS m Doc
543highlightCode opts attr str =
547highlightCode opts attr str =
544− case highlight (writerSyntaxMap opts) msFormatter attr str of
548+ case highlight (writerSyntaxMap opts) (msFormatter opts) attr str of
545 Left msg -> do
549 Left msg -> do
546 unless (null msg) $ report $ CouldNotHighlight msg
550 unless (null msg) $ report $ CouldNotHighlight msg
547− return $ text (escapeCode str)
551+ return $ text (escapeCode (writerPreferAscii opts) str)
548 Right h -> do
552 Right h -> do
549 modify (\st -> st{ stHighlighting = True })
553 modify (\st -> st{ stHighlighting = True })