@@ -44,6 +44,7 @@ module Text.Pandoc.Shared (
4444 camelCaseToHyphenated,
4545 toRomanNumeral,
4646 escapeURI,
47+ unescapeURI,
4748 wrapped,
4849 wrapIfNeeded,
4950 wrappedTeX,
@@ -118,8 +119,8 @@ import Text.Pandoc.CharacterReferences ( characterReference )
118119import Data.Char ( toLower, toUpper, ord, isLower, isUpper, isAlpha, isAscii,
119120 isPunctuation )
120121import Data.List ( find, isPrefixOf, intercalate )
121−import Network.URI ( parseURI, URI (..), isAllowedInURI, escapeURIString )
122−import Codec.Binary.UTF8.String ( encodeString )
122+import Network.URI ( parseURI, URI (..), isAllowedInURI, escapeURIString, unEscapeString )
123+import Codec.Binary.UTF8.String ( encodeString, decodeString )
123124import System.Directory
124125import System.FilePath ( (</>) )
125126-- Note: ghc >= 6.12 (base >=4.2) supports unicode through iconv
@@ -236,6 +237,12 @@ toRomanNumeral x =
236237escapeURI :: String -> String
237238escapeURI = escapeURIString isAllowedInURI . encodeString
238239
240+-- | Unescape unicode and some special characters in a URI, but
241+-- without introducing spaces.
242+unescapeURI :: String -> String
243+unescapeURI = escapeURIString (\c -> isAllowedInURI c || not (isAscii c)) .
244+ decodeString . unEscapeString
245+
239246-- | Wrap inlines to line length.
240247wrapped :: Monad m => ([Inline] -> m Doc) -> [Inline] -> m Doc
241248wrapped listWriter sect = (mapM listWriter $ splitBy Space sect) >>=