@@ -115,10 +115,11 @@ import Text.ParserCombinators.Parsec
115import Text.PrettyPrint.HughesPJ ( Doc, fsep, ($$), (<>), empty, isEmpty, text, nest )
115import Text.PrettyPrint.HughesPJ ( Doc, fsep, ($$), (<>), empty, isEmpty, text, nest )
116import qualified Text.PrettyPrint.HughesPJ as PP
116import qualified Text.PrettyPrint.HughesPJ as PP
117import Text.Pandoc.CharacterReferences ( characterReference )
117import 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,
119 isPunctuation )
119 isPunctuation )
120import Data.List ( find, isPrefixOf, intercalate )
120import 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 )
122import System.Directory
123import System.Directory
123import System.FilePath ( (</>) )
124import System.FilePath ( (</>) )
124-- Note: ghc >= 6.12 (base >=4.2) supports unicode through iconv
125-- Note: ghc >= 6.12 (base >=4.2) supports unicode through iconv
@@ -131,10 +132,6 @@ import System.IO.UTF8
131import Data.Generics
132import Data.Generics
132import qualified Control.Monad.State as S
133import qualified Control.Monad.State as S
133import Control.Monad (join)
134import Control.Monad (join)
134−import Data.ByteString (unpack)
135−import Data.Word (Word8)
136−import Data.ByteString.UTF8 (fromString)
137−import Text.Printf (printf)
138import Paths_pandoc (getDataFileName)
135import Paths_pandoc (getDataFileName)
@@ -234,15 +231,10 @@ toRomanNumeral x =
234 _ | x >= 1 -> "I" ++ toRomanNumeral (x - 1)
231 _ | x >= 1 -> "I" ++ toRomanNumeral (x - 1)
237−-- | Escape unicode characters in a URI. This means converting
234+-- | Escape unicode characters in a URI. Characters that are
238−-- them to UTF-8, then URI-encoding the octets. We leave everything
235+-- already valid in a URI, including % and ?, are left alone.
239−-- else the same, assuming that the user has already escaped
240−-- special characters like & and %.
241stringToURI :: String -> String
236stringToURI :: String -> String
242−stringToURI = concatMap encodeOctet . unpack . fromString
237+stringToURI = escapeURIString isAllowedInURI . encodeString
243− where encodeOctet :: Word8 -> String
244− encodeOctet x | x > 127 = printf "%%%2x" x
245− encodeOctet x = [chr (fromIntegral x)]
247-- | Wrap inlines to line length.
239-- | Wrap inlines to line length.
248wrapped :: Monad m => ([Inline] -> m Doc) -> [Inline] -> m Doc
240wrapped :: Monad m => ([Inline] -> m Doc) -> [Inline] -> m Doc