diff options
author | fiddlosopher <fiddlosopher@788f1e2b-df1e-0410-8736-df70ead52e1b> | 2008-11-01 21:05:33 +0000 |
---|---|---|
committer | fiddlosopher <fiddlosopher@788f1e2b-df1e-0410-8736-df70ead52e1b> | 2008-11-01 21:05:33 +0000 |
commit | 0e4eb8374992298366b6b003b5f97c7cd8868349 (patch) | |
tree | 6eee4db2e9ad133f7063855e23e6e311f0d26523 /Text/Pandoc/Readers | |
parent | c43e40904e6a88a1e0f6f286dd223fcdf82d51bd (diff) | |
download | pandoc-0e4eb8374992298366b6b003b5f97c7cd8868349.tar.gz |
Markdown reader: cleaner handling of spaces in URLs.
Consecutive spaces are now collapsed into one %20, and
final spaces are removed. Also, a test case has been added.
git-svn-id: https://pandoc.googlecode.com/svn/trunk@1477 788f1e2b-df1e-0410-8736-df70ead52e1b
Diffstat (limited to 'Text/Pandoc/Readers')
-rw-r--r-- | Text/Pandoc/Readers/Markdown.hs | 17 |
1 files changed, 6 insertions, 11 deletions
diff --git a/Text/Pandoc/Readers/Markdown.hs b/Text/Pandoc/Readers/Markdown.hs index 08e78d525..205472d29 100644 --- a/Text/Pandoc/Readers/Markdown.hs +++ b/Text/Pandoc/Readers/Markdown.hs @@ -32,7 +32,6 @@ module Text.Pandoc.Readers.Markdown ( readMarkdown ) where -import Control.Applicative ( (<$>) ) import Data.List ( transpose, isPrefixOf, isSuffixOf, lookup, sortBy, findIndex, intercalate ) import Data.Ord ( comparing ) import Data.Char ( isAlphaNum, isAlpha, isLower, isDigit, isUpper ) @@ -189,15 +188,13 @@ referenceKey = try $ do lab <- reference char ':' skipSpaces >> optional newline >> skipSpaces >> notFollowedBy (char '[') - let sourceURL excludes = concat <$> - (many $ do optional (char '\\') - count 1 (noneOf $ ' ':excludes) - <|> (notFollowedBy' referenceTitle >> char ' ' >> return "%20")) + let sourceURL excludes = many $ + optional (char '\\') >> (noneOf (' ':excludes) <|> (notFollowedBy' referenceTitle >> char ' ')) src <- try (char '<' >> sourceURL ">\t\n" >>~ char '>') <|> sourceURL "\t\n" tit <- option "" referenceTitle blanklines endPos <- getPosition - let newkey = (lab, (removeTrailingSpace src, tit)) + let newkey = (lab, (intercalate "%20" $ words $ removeTrailingSpace src, tit)) st <- getState let oldkeys = stateKeys st updateState $ \s -> s { stateKeys = newkey : oldkeys } @@ -1066,15 +1063,13 @@ source = source' :: GenParser Char st (String, [Char]) source' = do skipSpaces - let sourceURL excludes = concat <$> - (many $ do optional (char '\\') - count 1 (noneOf $ ' ':excludes) - <|> (notFollowedBy' linkTitle >> char ' ' >> return "%20")) + let sourceURL excludes = many $ + optional (char '\\') >> (noneOf (' ':excludes) <|> (notFollowedBy' linkTitle >> char ' ')) src <- try (char '<' >> sourceURL ">\t\n" >>~ char '>') <|> sourceURL "\t\n" tit <- option "" linkTitle skipSpaces eof - return (removeTrailingSpace src, tit) + return (intercalate "%20" $ words $ removeTrailingSpace src, tit) linkTitle :: GenParser Char st String linkTitle = try $ do |