git.iko.soy/typeable/pandoc
on master help sign in
Ms writer link improvements.
16439c8John MacFarlane
src/Text/Pandoc/Writers/Ms.hs+13−5
@@ -217,11 +217,16 @@ blockToMs :: PandocMonad m
217 -> Block -- ^ Block element
217 -> Block -- ^ Block element
218 -> MS m Doc
218 -> MS m Doc
219blockToMs _ Null = return empty
219blockToMs _ 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))
221 setFirstPara
226 setFirstPara
222 res <- blockListToMs opts bs
227 res <- blockListToMs opts bs
223 setFirstPara
228 setFirstPara
224− return res
229+ return $ anchor $$ res
225blockToMs opts (Plain inlines) =
230blockToMs opts (Plain inlines) =
226 liftM vcat $ mapM (inlineListToMs' opts) $ splitSentences inlines
231 liftM vcat $ mapM (inlineListToMs' opts) $ splitSentences inlines
227blockToMs opts (Para [Image attr alt (src,_tit)])
232blockToMs opts (Para [Image attr alt (src,_tit)])
@@ -640,7 +645,10 @@ highlightCode opts attr str =
640 modify (\st -> st{ stHighlighting = True })
645 modify (\st -> st{ stHighlighting = True })
641 return h
646 return h
642
647
648+-- This is used for PDF anchors.
643toAscii :: String -> String
649toAscii :: String -> String
650+toAscii = concatMap
644−toAscii = concatMap (\c -> case toAsciiChar c of
651+ (\c -> case toAsciiChar c of
652+ Nothing -> '_':'u':show (ord c) ++ "_"
645− Nothing -> 'u':show (ord c)
653+ Just '/' -> '_':'u':show (ord c) ++ "_" -- see #4515
646− Just c' -> [c'])
654+ Just c' -> [c'])