aboutsummaryrefslogtreecommitdiff
path: root/src/Text/Pandoc
diff options
context:
space:
mode:
authorJohn MacFarlane <jgm@berkeley.edu>2010-03-23 15:34:53 -0700
committerJohn MacFarlane <jgm@berkeley.edu>2010-03-23 15:34:53 -0700
commit85040553607d3f796e73e5eb23c9d9ac5d62ff9b (patch)
tree8c3cdeb6d242157bce87949285d08afb4f76f7ee /src/Text/Pandoc
parentc87d52223ad97ae7f21c69b09ec7b1467bd35670 (diff)
downloadpandoc-85040553607d3f796e73e5eb23c9d9ac5d62ff9b.tar.gz
Shared: Export unescapeURI.
Diffstat (limited to 'src/Text/Pandoc')
-rw-r--r--src/Text/Pandoc/Shared.hs11
1 files changed, 9 insertions, 2 deletions
diff --git a/src/Text/Pandoc/Shared.hs b/src/Text/Pandoc/Shared.hs
index 72772303e..54d3f9a43 100644
--- a/src/Text/Pandoc/Shared.hs
+++ b/src/Text/Pandoc/Shared.hs
@@ -44,6 +44,7 @@ module Text.Pandoc.Shared (
camelCaseToHyphenated,
toRomanNumeral,
escapeURI,
+ unescapeURI,
wrapped,
wrapIfNeeded,
wrappedTeX,
@@ -118,8 +119,8 @@ import Text.Pandoc.CharacterReferences ( characterReference )
import Data.Char ( toLower, toUpper, ord, isLower, isUpper, isAlpha, isAscii,
isPunctuation )
import Data.List ( find, isPrefixOf, intercalate )
-import Network.URI ( parseURI, URI (..), isAllowedInURI, escapeURIString )
-import Codec.Binary.UTF8.String ( encodeString )
+import Network.URI ( parseURI, URI (..), isAllowedInURI, escapeURIString, unEscapeString )
+import Codec.Binary.UTF8.String ( encodeString, decodeString )
import System.Directory
import System.FilePath ( (</>) )
-- Note: ghc >= 6.12 (base >=4.2) supports unicode through iconv
@@ -236,6 +237,12 @@ toRomanNumeral x =
escapeURI :: String -> String
escapeURI = escapeURIString isAllowedInURI . encodeString
+-- | Unescape unicode and some special characters in a URI, but
+-- without introducing spaces.
+unescapeURI :: String -> String
+unescapeURI = escapeURIString (\c -> isAllowedInURI c || not (isAscii c)) .
+ decodeString . unEscapeString
+
-- | Wrap inlines to line length.
wrapped :: Monad m => ([Inline] -> m Doc) -> [Inline] -> m Doc
wrapped listWriter sect = (mapM listWriter $ splitBy Space sect) >>=