git.iko.soy/typeable/pandoc
on master help sign in
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.

commit16439c879e21749e96d8f7a0ed58c87b0c235cb0 authorJohn MacFarlane <jgm@berkeley.edu> dateSat 14 Apr 2018, 10:59 (9 years ago) parentd5b98c8
1 file changed+13−5
src/Text/Pandoc/Writers/Ms.hs+13−5
src/Text/Pandoc/Writers/Ms.hs+13−5
@@ -217,11 +217,16 @@ blockToMs :: PandocMonad m
217217 -> Block -- ^ Block element
218218 -> MS m Doc
219219blockToMs _ Null = return empty
220−blockToMs opts (Div _ bs) = do
220+blockToMs opts (Div (ident,_,_) bs) = do
221+ let anchor = if null ident
222+ then empty
223+ else nowrap $
224+ text ".pdfhref M "
225+ <> doubleQuotes (text (toAscii ident))
221226 setFirstPara
222227 res <- blockListToMs opts bs
223228 setFirstPara
224− return res
229+ return $ anchor $$ res
225230blockToMs opts (Plain inlines) =
226231 liftM vcat $ mapM (inlineListToMs' opts) $ splitSentences inlines
227232blockToMs opts (Para [Image attr alt (src,_tit)])
@@ -640,7 +645,10 @@ highlightCode opts attr str =
640645 modify (\st -> st{ stHighlighting = True })
641646 return h
642647
648+-- This is used for PDF anchors.
643649toAscii :: String -> String
644−toAscii = concatMap (\c -> case toAsciiChar c of
645− Nothing -> 'u':show (ord c)
646− Just c' -> [c'])
650+toAscii = concatMap
651+ (\c -> case toAsciiChar c of
652+ Nothing -> '_':'u':show (ord c) ++ "_"
653+ Just '/' -> '_':'u':show (ord c) ++ "_" -- see #4515
654+ Just c' -> [c'])