@@ -44,6 +44,7 @@ module Text.Pandoc.Shared (
44 camelCaseToHyphenated,
44 camelCaseToHyphenated,
45 toRomanNumeral,
45 toRomanNumeral,
46 escapeURI,
46 escapeURI,
48 wrapIfNeeded,
49 wrapIfNeeded,
49 wrappedTeX,
50 wrappedTeX,
@@ -118,8 +119,8 @@ import Text.Pandoc.CharacterReferences ( characterReference )
118import Data.Char ( toLower, toUpper, ord, isLower, isUpper, isAlpha, isAscii,
119import Data.Char ( toLower, toUpper, ord, isLower, isUpper, isAlpha, isAscii,
119 isPunctuation )
120 isPunctuation )
120import Data.List ( find, isPrefixOf, intercalate )
121import Data.List ( find, isPrefixOf, intercalate )
121−import Network.URI ( parseURI, URI (..), isAllowedInURI, escapeURIString )
122+import Network.URI ( parseURI, URI (..), isAllowedInURI, escapeURIString, unEscapeString )
122−import Codec.Binary.UTF8.String ( encodeString )
123+import Codec.Binary.UTF8.String ( encodeString, decodeString )
123import System.Directory
124import System.Directory
124import System.FilePath ( (</>) )
125import System.FilePath ( (</>) )
125-- Note: ghc >= 6.12 (base >=4.2) supports unicode through iconv
126-- Note: ghc >= 6.12 (base >=4.2) supports unicode through iconv
@@ -236,6 +237,12 @@ toRomanNumeral x =
236escapeURI :: String -> String
237escapeURI :: String -> String
237escapeURI = escapeURIString isAllowedInURI . encodeString
238escapeURI = escapeURIString isAllowedInURI . encodeString
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
239-- | Wrap inlines to line length.
246-- | Wrap inlines to line length.
240wrapped :: Monad m => ([Inline] -> m Doc) -> [Inline] -> m Doc
247wrapped :: Monad m => ([Inline] -> m Doc) -> [Inline] -> m Doc
241wrapped listWriter sect = (mapM listWriter $ splitBy Space sect) >>=
248wrapped listWriter sect = (mapM listWriter $ splitBy Space sect) >>=