aboutsummaryrefslogtreecommitdiff
path: root/src/Text
diff options
context:
space:
mode:
authorJohn MacFarlane <jgm@berkeley.edu>2018-04-14 10:59:01 -0700
committerJohn MacFarlane <jgm@berkeley.edu>2018-04-14 10:59:01 -0700
commit16439c879e21749e96d8f7a0ed58c87b0c235cb0 (patch)
tree45668ef635f409d454ca50d94e149c6d41082a6a /src/Text
parentd5b98c8c6ec13556911876ac5632efb63a1ce40d (diff)
downloadpandoc-16439c879e21749e96d8f7a0ed58c87b0c235cb0.tar.gz
Ms writer link improvements.
+ Create pdf anchor for a Div with an identifier. + Escape `/` character in anchor ids. + Improve escaping for anchor ids: we now use _uNNN_ instead of uNNN to avoid ambiguity. This is intended to help with #4515; however, in my tests, the link to the reference does not seem to work. I'm not sure why.
Diffstat (limited to 'src/Text')
-rw-r--r--src/Text/Pandoc/Writers/Ms.hs18
1 files changed, 13 insertions, 5 deletions
diff --git a/src/Text/Pandoc/Writers/Ms.hs b/src/Text/Pandoc/Writers/Ms.hs
index 75c904245..4731d4a9f 100644
--- a/src/Text/Pandoc/Writers/Ms.hs
+++ b/src/Text/Pandoc/Writers/Ms.hs
@@ -217,11 +217,16 @@ blockToMs :: PandocMonad m
-> Block -- ^ Block element
-> MS m Doc
blockToMs _ Null = return empty
-blockToMs opts (Div _ bs) = do
+blockToMs opts (Div (ident,_,_) bs) = do
+ let anchor = if null ident
+ then empty
+ else nowrap $
+ text ".pdfhref M "
+ <> doubleQuotes (text (toAscii ident))
setFirstPara
res <- blockListToMs opts bs
setFirstPara
- return res
+ return $ anchor $$ res
blockToMs opts (Plain inlines) =
liftM vcat $ mapM (inlineListToMs' opts) $ splitSentences inlines
blockToMs opts (Para [Image attr alt (src,_tit)])
@@ -640,7 +645,10 @@ highlightCode opts attr str =
modify (\st -> st{ stHighlighting = True })
return h
+-- This is used for PDF anchors.
toAscii :: String -> String
-toAscii = concatMap (\c -> case toAsciiChar c of
- Nothing -> 'u':show (ord c)
- Just c' -> [c'])
+toAscii = concatMap
+ (\c -> case toAsciiChar c of
+ Nothing -> '_':'u':show (ord c) ++ "_"
+ Just '/' -> '_':'u':show (ord c) ++ "_" -- see #4515
+ Just c' -> [c'])