aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn MacFarlane <jgm@berkeley.edu>2018-03-09 09:27:44 -0800
committerJohn MacFarlane <jgm@berkeley.edu>2018-03-09 09:27:44 -0800
commit0bdabfb09abe96781d72b038c2c40f69901bf0b8 (patch)
tree31d8752c8b4c60f28fecd3b9fd64f7c9e9cdafc3
parentef9b8c3ede0a5c97a9c9502fe00b79a9068aaeac (diff)
downloadpandoc-0bdabfb09abe96781d72b038c2c40f69901bf0b8.tar.gz
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.
-rw-r--r--src/Text/Pandoc/Writers/Ms.hs15
1 files changed, 11 insertions, 4 deletions
diff --git a/src/Text/Pandoc/Writers/Ms.hs b/src/Text/Pandoc/Writers/Ms.hs
index 83d80cd4a..558576876 100644
--- a/src/Text/Pandoc/Writers/Ms.hs
+++ b/src/Text/Pandoc/Writers/Ms.hs
@@ -37,7 +37,7 @@ TODO:
module Text.Pandoc.Writers.Ms ( writeMs ) where
import Control.Monad.State.Strict
-import Data.Char (isLower, isUpper, toUpper)
+import Data.Char (isLower, isUpper, toUpper, ord)
import Data.List (intercalate, intersperse, sort)
import qualified Data.Map as Map
import Data.Maybe (catMaybes, fromMaybe)
@@ -46,6 +46,7 @@ import qualified Data.Text as T
import Network.URI (escapeURIString, isAllowedInURI)
import Skylighting
import System.FilePath (takeExtension)
+import Text.Pandoc.Asciify (toAsciiChar)
import Text.Pandoc.Class (PandocMonad, report)
import Text.Pandoc.Definition
import Text.Pandoc.Highlighting
@@ -266,7 +267,8 @@ blockToMs opts (Header level (ident,classes,_) inlines) = do
let anchor = if null ident
then empty
else nowrap $
- text ".pdfhref M " <> doubleQuotes (text ident)
+ text ".pdfhref M "
+ <> doubleQuotes (text (toAscii ident))
let bookmark = text ".pdfhref O " <> text (show level ++ " ") <>
doubleQuotes (text $ secnum ++
(if null secnum
@@ -274,7 +276,7 @@ blockToMs opts (Header level (ident,classes,_) inlines) = do
else " ") ++
escapeString (stringify inlines))
let backlink = nowrap (text ".pdfhref L -D " <>
- doubleQuotes (text ident) <> space <> text "\\") <> cr <>
+ doubleQuotes (text (toAscii ident)) <> space <> text "\\") <> cr <>
text " -- "
let tocEntry = if writerTableOfContents opts &&
level <= writerTOCDepth opts
@@ -513,7 +515,7 @@ inlineToMs opts (Link _ txt ('#':ident, _)) = do
-- internal link
contents <- inlineListToMs' opts $ map breakToSpace txt
return $ text "\\c" <> cr <> nowrap (text ".pdfhref L -D " <>
- doubleQuotes (text ident) <> text " -A " <>
+ doubleQuotes (text (toAscii ident)) <> text " -A " <>
doubleQuotes (text "\\c") <> space <> text "\\") <> cr <>
text " -- " <> doubleQuotes (nowrap contents) <> cr <> text "\\&"
inlineToMs opts (Link _ txt (src, _)) = do
@@ -637,3 +639,8 @@ highlightCode opts attr str =
Right h -> do
modify (\st -> st{ stHighlighting = True })
return h
+
+toAscii :: String -> String
+toAscii = concatMap (\c -> case toAsciiChar c of
+ Nothing -> 'u':show (ord c)
+ Just c' -> [c'])