Ms writer: ensure that @ is escaped in URIs.

Otherwise we may get unescaped @s that give eqn fits,
with @ as the delimiter character.
This commit is contained in:
John MacFarlane 2017-04-04 16:13:24 +02:00
parent e650d1fbfd
commit 1ebb766aff
2 changed files with 7 additions and 3 deletions

View file

@ -57,6 +57,7 @@ import Text.TeXMath (writeEqn)
import System.FilePath (takeExtension)
import Skylighting
import Text.Pandoc.Highlighting
import Network.URI (escapeURIString, isAllowedInURI)
data WriterState = WriterState { stHasInlineMath :: Bool
, stFirstPara :: Bool
@ -157,6 +158,9 @@ escapeBar = concatMap go
escapeString :: String -> String
escapeString = concatMap escapeChar
escapeUri :: String -> String
escapeUri = escapeURIString (\c -> c /= '@' && isAllowedInURI c)
toSmallCaps :: String -> String
toSmallCaps [] = []
toSmallCaps (c:cs)
@ -509,7 +513,7 @@ inlineToMs opts (Link _ txt (src, _)) = do
-- external link
contents <- inlineListToMs' opts $ map breakToSpace txt
return $ text "\\c" <> cr <> nowrap (text ".pdfhref W -D " <>
doubleQuotes (text src) <> text " -A " <>
doubleQuotes (text (escapeUri src)) <> text " -A " <>
doubleQuotes (text "\\c") <> space <> text "\\") <> cr <>
text " -- " <> doubleQuotes (nowrap contents) <> cr <> text "\\&"
inlineToMs opts (Image attr alternate (source, tit)) = do

View file

@ -829,7 +829,7 @@ Just a \c
\&
.PP
\c
.pdfhref W -D "mailto:nobody@nowhere.net" -A "\c" \
.pdfhref W -D "mailto:nobody%40nowhere.net" -A "\c" \
-- "Email link"
\&
.PP
@ -943,7 +943,7 @@ In a list?
It should.
.LP
An e\-mail address: \c
.pdfhref W -D "mailto:nobody@nowhere.net" -A "\c" \
.pdfhref W -D "mailto:nobody%40nowhere.net" -A "\c" \
-- "nobody\@nowhere.net"
\&
.RS