@@ -115,10 +115,11 @@ import Text.ParserCombinators.Parsec
115115import Text.PrettyPrint.HughesPJ ( Doc, fsep, ($$), (<>), empty, isEmpty, text, nest )
116116import qualified Text.PrettyPrint.HughesPJ as PP
117117import Text.Pandoc.CharacterReferences ( characterReference )
118−import Data.Char ( toLower, toUpper, ord, chr, isLower, isUpper, isAlpha,
118+import Data.Char ( toLower, toUpper, ord, isLower, isUpper, isAlpha,
119119 isPunctuation )
120120import Data.List ( find, isPrefixOf, intercalate )
121−import Network.URI ( parseURI, URI (..), isAllowedInURI )
121+import Network.URI ( parseURI, URI (..), isAllowedInURI, escapeURIString )
122+import Codec.Binary.UTF8.String ( encodeString )
122123import System.Directory
123124import System.FilePath ( (</>) )
124125-- Note: ghc >= 6.12 (base >=4.2) supports unicode through iconv
@@ -131,10 +132,6 @@ import System.IO.UTF8
131132import Data.Generics
132133import qualified Control.Monad.State as S
133134import Control.Monad (join)
134−import Data.ByteString (unpack)
135−import Data.Word (Word8)
136−import Data.ByteString.UTF8 (fromString)
137−import Text.Printf (printf)
138135import Paths_pandoc (getDataFileName)
139136
140137--
@@ -234,15 +231,10 @@ toRomanNumeral x =
234231 _ | x >= 1 -> "I" ++ toRomanNumeral (x - 1)
235232 _ -> ""
236233
237−-- | Escape unicode characters in a URI. This means converting
238−-- them to UTF-8, then URI-encoding the octets. We leave everything
239−-- else the same, assuming that the user has already escaped
240−-- special characters like & and %.
234+-- | Escape unicode characters in a URI. Characters that are
235+-- already valid in a URI, including % and ?, are left alone.
241236stringToURI :: String -> String
242−stringToURI = concatMap encodeOctet . unpack . fromString
243− where encodeOctet :: Word8 -> String
244− encodeOctet x | x > 127 = printf "%%%2x" x
245− encodeOctet x = [chr (fromIntegral x)]
237+stringToURI = escapeURIString isAllowedInURI . encodeString
246238
247239-- | Wrap inlines to line length.
248240wrapped :: Monad m => ([Inline] -> m Doc) -> [Inline] -> m Doc