git.iko.soy/typeable/pandoc
on master help sign in
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

commit0e4eb8374992298366b6b003b5f97c7cd8868349 authorfiddlosopher <fiddlosopher@788f1e2b-df1e-0410-8736-df70ead52e1b> dateSat 1 Nov 2008, 21:05 (18 years ago) parentc43e409
4 files changed+25−13
Text/Pandoc/Readers/Markdown.hs+6−11 changelog+2−1 tests/markdown-reader-more.native+4−1 tests/markdown-reader-more.txt+13
Text/Pandoc/Readers/Markdown.hs+6−11
@@ -32,7 +32,6 @@ module Text.Pandoc.Readers.Markdown (
3232 readMarkdown
3333 ) where
3434
35−import Control.Applicative ( (<$>) )
3635import Data.List ( transpose, isPrefixOf, isSuffixOf, lookup, sortBy, findIndex, intercalate )
3736import Data.Ord ( comparing )
3837import Data.Char ( isAlphaNum, isAlpha, isLower, isDigit, isUpper )
@@ -189,15 +188,13 @@ referenceKey = try $ do
189188 lab <- reference
190189 char ':'
191190 skipSpaces >> optional newline >> skipSpaces >> notFollowedBy (char '[')
192− let sourceURL excludes = concat <$>
193− (many $ do optional (char '\\')
194− count 1 (noneOf $ ' ':excludes)
195− <|> (notFollowedBy' referenceTitle >> char ' ' >> return "%20"))
191+ let sourceURL excludes = many $
192+ optional (char '\\') >> (noneOf (' ':excludes) <|> (notFollowedBy' referenceTitle >> char ' '))
196193 src <- try (char '<' >> sourceURL ">\t\n" >>~ char '>') <|> sourceURL "\t\n"
197194 tit <- option "" referenceTitle
198195 blanklines
199196 endPos <- getPosition
200− let newkey = (lab, (removeTrailingSpace src, tit))
197+ let newkey = (lab, (intercalate "%20" $ words $ removeTrailingSpace src, tit))
201198 st <- getState
202199 let oldkeys = stateKeys st
203200 updateState $ \s -> s { stateKeys = newkey : oldkeys }
@@ -1066,15 +1063,13 @@ source =
10661063source' :: GenParser Char st (String, [Char])
10671064source' = do
10681065 skipSpaces
1069− let sourceURL excludes = concat <$>
1070− (many $ do optional (char '\\')
1071− count 1 (noneOf $ ' ':excludes)
1072− <|> (notFollowedBy' linkTitle >> char ' ' >> return "%20"))
1066+ let sourceURL excludes = many $
1067+ optional (char '\\') >> (noneOf (' ':excludes) <|> (notFollowedBy' linkTitle >> char ' '))
10731068 src <- try (char '<' >> sourceURL ">\t\n" >>~ char '>') <|> sourceURL "\t\n"
10741069 tit <- option "" linkTitle
10751070 skipSpaces
10761071 eof
1077− return (removeTrailingSpace src, tit)
1072+ return (intercalate "%20" $ words $ removeTrailingSpace src, tit)
10781073
10791074linkTitle :: GenParser Char st String
10801075linkTitle = try $ do
changelog+2−1
@@ -49,7 +49,8 @@ pandoc (1.1)
4949 a blank line before the haskell code, and we don't want spurious
5050 blank lines in the output.
5151
52− + Allow URLs with spaces in them in links and references.
52+ + Allow URLs with spaces in them in links and references, but escape
53+ them as "%20".
5354
5455 * HTML writer:
5556
tests/markdown-reader-more.native+4−1
@@ -4,5 +4,8 @@ Pandoc (Meta [] [] "")
44, Para [Link [Str "foo"] ("/url",""),Space,Str "and",Space,Link [Str "bar"] ("/url","title")]
55, Header 2 [Str "Raw",Space,Str "ConTeXt",Space,Str "environments"]
66, Para [TeX "\\placeformula",Space,TeX "\\startformula\n L_{1} = L_{2}\n \\stopformula"]
7−, Para [TeX "\\start[a2]\n\\start[a2]\n\\stop[a2]\n\\stop[a2]"] ]
7+, Para [TeX "\\start[a2]\n\\start[a2]\n\\stop[a2]\n\\stop[a2]"]
8+, Header 2 [Str "URLs",Space,Str "with",Space,Str "spaces"]
9+, Para [Link [Str "foo"] ("/bar%20and%20baz",""),Space,Link [Str "foo"] ("/bar%20and%20baz",""),Space,Link [Str "foo"] ("/bar%20and%20baz",""),Space,Link [Str "foo"] ("bar%20baz","title")]
10+, Para [Link [Str "baz"] ("/foo%20foo",""),Space,Link [Str "bam"] ("/foo%20fee",""),Space,Link [Str "bork"] ("/foo/zee%20zob","title")] ]
811
tests/markdown-reader-more.txt+13
@@ -22,3 +22,16 @@
2222\stop[a2]
2323\stop[a2]
2424
25+## URLs with spaces
26+
27+[foo](/bar and baz)
28+[foo](/bar and baz )
29+[foo]( /bar and baz )
30+[foo](bar baz "title" )
31+
32+[baz][] [bam][] [bork][]
33+
34+[baz]: /foo foo
35+[bam]: /foo fee
36+[bork]: /foo/zee zob (title)
37+