git.iko.soy/typeable/pandoc
on master help sign in
Markdown reader: Use simpler approach for URLs - just escape spaces.

Markdown.pl doesn't URI-escape anything, so we won't do that either, except for spaces, which can cause problems if not escaped. Resolves Issue #220 and partially reverts r1847. git-svn-id: https://pandoc.googlecode.com/svn/trunk@1851 788f1e2b-df1e-0410-8736-df70ead52e1b

commitddcde4d543f865fa95d2a6bb4ca2dfdfc4435c13 authorfiddlosopher <fiddlosopher@788f1e2b-df1e-0410-8736-df70ead52e1b> dateSat 27 Feb 2010, 04:59 (17 years ago) parentf2552cf
1 file changed+5−9
src/Text/Pandoc/Readers/Markdown.hs+5−9
src/Text/Pandoc/Readers/Markdown.hs+5−9
@@ -45,7 +45,6 @@ import Text.Pandoc.Readers.HTML ( rawHtmlBlock, anyHtmlBlockTag,
4545import Text.Pandoc.CharacterReferences ( decodeCharacterReferences )
4646import Text.ParserCombinators.Parsec
4747import Control.Monad (when, liftM, unless)
48−import Network.URI ( unEscapeString, escapeURIString, isUnescapedInURI )
4948
5049-- | Read markdown from an input string and return a Pandoc document.
5150readMarkdown :: ParserState -- ^ Parser state, including options for parser
@@ -74,12 +73,9 @@ specialChars = "\\[]*_~`<>$!^-.&'\"\8216\8217\8220\8221;"
7473-- auxiliary functions
7574--
7675
77−-- | Escape a URI in a markdown-appropriate way. First,
78−-- we unescape the string, since we don't want to screw things
79−-- up if they've entered a properly encoded URI. Then, we
80−-- escape the result.
81−escapeURI :: String -> String
82−escapeURI = escapeURIString isUnescapedInURI . unEscapeString
76+-- | Replace spaces with %20
77+uriEscapeSpaces :: String -> String
78+uriEscapeSpaces = substitute " " "%20"
8379
8480indentSpaces :: GenParser Char ParserState [Char]
8581indentSpaces = try $ do
@@ -202,7 +198,7 @@ referenceKey = try $ do
202198 tit <- option "" referenceTitle
203199 blanklines
204200 endPos <- getPosition
205− let newkey = (lab, (escapeURI $ removeTrailingSpace src, tit))
201+ let newkey = (lab, (uriEscapeSpaces $ removeTrailingSpace src, tit))
206202 st <- getState
207203 let oldkeys = stateKeys st
208204 updateState $ \s -> s { stateKeys = newkey : oldkeys }
@@ -1181,7 +1177,7 @@ source' = do
11811177 tit <- option "" linkTitle
11821178 skipSpaces
11831179 eof
1184− return (escapeURI $ removeTrailingSpace src, tit)
1180+ return (uriEscapeSpaces $ removeTrailingSpace src, tit)
11851181
11861182linkTitle :: GenParser Char st String
11871183linkTitle = try $ do