git.iko.soy/typeable/pandoc
on master help sign in
Ms writer: asciify pdf anchors, since unicode anchors don't work.

Closes #4436. Internal links should be converted automatically, so this shouldn't affect users directly.

commit0bdabfb09abe96781d72b038c2c40f69901bf0b8 authorJohn MacFarlane <jgm@berkeley.edu> dateFri 9 Mar 2018, 09:27 (9 years ago) parentef9b8c3
1 file changed+11−4
src/Text/Pandoc/Writers/Ms.hs+11−4
src/Text/Pandoc/Writers/Ms.hs+11−4
@@ -37,7 +37,7 @@ TODO:
3737
3838module Text.Pandoc.Writers.Ms ( writeMs ) where
3939import Control.Monad.State.Strict
40−import Data.Char (isLower, isUpper, toUpper)
40+import Data.Char (isLower, isUpper, toUpper, ord)
4141import Data.List (intercalate, intersperse, sort)
4242import qualified Data.Map as Map
4343import Data.Maybe (catMaybes, fromMaybe)
@@ -46,6 +46,7 @@ import qualified Data.Text as T
4646import Network.URI (escapeURIString, isAllowedInURI)
4747import Skylighting
4848import System.FilePath (takeExtension)
49+import Text.Pandoc.Asciify (toAsciiChar)
4950import Text.Pandoc.Class (PandocMonad, report)
5051import Text.Pandoc.Definition
5152import Text.Pandoc.Highlighting
@@ -266,7 +267,8 @@ blockToMs opts (Header level (ident,classes,_) inlines) = do
266267 let anchor = if null ident
267268 then empty
268269 else nowrap $
269− text ".pdfhref M " <> doubleQuotes (text ident)
270+ text ".pdfhref M "
271+ <> doubleQuotes (text (toAscii ident))
270272 let bookmark = text ".pdfhref O " <> text (show level ++ " ") <>
271273 doubleQuotes (text $ secnum ++
272274 (if null secnum
@@ -274,7 +276,7 @@ blockToMs opts (Header level (ident,classes,_) inlines) = do
274276 else " ") ++
275277 escapeString (stringify inlines))
276278 let backlink = nowrap (text ".pdfhref L -D " <>
277− doubleQuotes (text ident) <> space <> text "\\") <> cr <>
279+ doubleQuotes (text (toAscii ident)) <> space <> text "\\") <> cr <>
278280 text " -- "
279281 let tocEntry = if writerTableOfContents opts &&
280282 level <= writerTOCDepth opts
@@ -513,7 +515,7 @@ inlineToMs opts (Link _ txt ('#':ident, _)) = do
513515 -- internal link
514516 contents <- inlineListToMs' opts $ map breakToSpace txt
515517 return $ text "\\c" <> cr <> nowrap (text ".pdfhref L -D " <>
516− doubleQuotes (text ident) <> text " -A " <>
518+ doubleQuotes (text (toAscii ident)) <> text " -A " <>
517519 doubleQuotes (text "\\c") <> space <> text "\\") <> cr <>
518520 text " -- " <> doubleQuotes (nowrap contents) <> cr <> text "\\&"
519521inlineToMs opts (Link _ txt (src, _)) = do
@@ -637,3 +639,8 @@ highlightCode opts attr str =
637639 Right h -> do
638640 modify (\st -> st{ stHighlighting = True })
639641 return h
642+
643+toAscii :: String -> String
644+toAscii = concatMap (\c -> case toAsciiChar c of
645+ Nothing -> 'u':show (ord c)
646+ Just c' -> [c'])