git.iko.soy/typeable/pandoc
on master help sign in
Textile reader/writer: Fixed autolinks.

Previously the textile reader and writer incorrectly implented RST-style autolinks for URLs and email addresses. This has been fixed. Now an autolink is done this way: "$":http://myurl.com

commit4cd573c61f61885cb368b40dccd1b458c39846c7 authorJohn MacFarlane <jgm@berkeley.edu> dateTue 6 Nov 2012, 16:05 (14 years ago) parent4aa3e1f
6 files changed+16−19
src/Text/Pandoc/Readers/Textile.hs+5−11 src/Text/Pandoc/Writers/Textile.hs+4−1 templates+1−1 tests/textile-reader.native+1−1 tests/textile-reader.textile+1−1 tests/writer.textile+4−4
src/Text/Pandoc/Readers/Textile.hs+5−11
@@ -46,7 +46,6 @@ Left to be implemented:
4646 - continued blocks (ex bq..)
4747
4848TODO : refactor common patterns across readers :
49− - autolink
5049 - more ...
5150
5251-}
@@ -361,8 +360,7 @@ inline = choice inlineParsers <?> "inline"
361360
362361-- | Inline parsers tried in order
363362inlineParsers :: [Parser [Char] ParserState Inline]
364−inlineParsers = [ autoLink
365− , str
363+inlineParsers = [ str
366364 , whitespace
367365 , endline
368366 , code
@@ -501,7 +499,8 @@ linkNoB = try $ do
501499 char ':'
502500 let stopChars = "!.,;:"
503501 url <- manyTill nonspaceChar (lookAhead $ space <|> try (oneOf stopChars >> (space <|> newline)))
504− return $ Link name (url, "")
502+ let name' = if name == [Str "$"] then [Str url] else name
503+ return $ Link name' (url, "")
505504
506505linkB :: Parser [Char] ParserState Inline
507506linkB = try $ do
@@ -509,13 +508,8 @@ linkB = try $ do
509508 name <- surrounded (char '"') inline
510509 char ':'
511510 url <- manyTill nonspaceChar (char ']')
512− return $ Link name (url, "")
513−
514−-- | Detect plain links to http or email.
515−autoLink :: Parser [Char] ParserState Inline
516−autoLink = do
517− (orig, src) <- (try uri <|> try emailAddress)
518− return $ Link [Str orig] (src, "")
511+ let name' = if name == [Str "$"] then [Str url] else name
512+ return $ Link name' (url, "")
519513
520514-- | image embedding
521515image :: Parser [Char] ParserState Inline
src/Text/Pandoc/Writers/Textile.hs+4−1
@@ -396,7 +396,10 @@ inlineToTextile _ Space = return " "
396396
397397inlineToTextile opts (Link txt (src, _)) = do
398398 label <- case txt of
399− [Code _ s] -> return s
399+ [Code _ s]
400+ | s == src -> return "$"
401+ [Str s]
402+ | s == src -> return "$"
400403 _ -> inlineListToTextile opts txt
401404 return $ "\"" ++ label ++ "\":" ++ src
402405
templates+1−1

Submodule changed.

tests/textile-reader.native+1−1
@@ -85,7 +85,7 @@ Pandoc (Meta {docTitle = [], docAuthors = [], docDate = []})
8585,Header 2 [Str "Explicit"]
8686,Para [Str "Just",Space,Str "a",Space,Link [Str "url"] ("http://www.url.com","")]
8787,Para [Link [Str "Email",Space,Str "link"] ("mailto:nobody@nowhere.net","")]
88−,Para [Str "Automatic",Space,Str "linking",Space,Str "to",Space,Link [Str "http://www.example.com"] ("http://www.example.com",""),Space,Str "and",Space,Link [Str "foobar@example.com"] ("mailto:foobar@example.com",""),Str "."]
88+,Para [Str "Automatic",Space,Str "linking",Space,Str "to",Space,Link [Str "http://www.example.com"] ("http://www.example.com",""),Str "."]
8989,Para [Link [Str "Example"] ("http://www.example.com/",""),Str ":",Space,Str "Example",Space,Str "of",Space,Str "a",Space,Str "link",Space,Str "followed",Space,Str "by",Space,Str "a",Space,Str "colon",Str "."]
9090,Para [Str "A",Space,Str "link",Link [Str "with",Space,Str "brackets"] ("http://www.example.com",""),Str "and",Space,Str "no",Space,Str "spaces",Str "."]
9191,Header 1 [Str "Tables"]
tests/textile-reader.textile+1−1
@@ -157,7 +157,7 @@ Just a "url":http://www.url.com
157157
158158"Email link":mailto:nobody@nowhere.net
159159
160−Automatic linking to http://www.example.com and foobar@example.com.
160+Automatic linking to "$":http://www.example.com.
161161
162162"Example":http://www.example.com/: Example of a link followed by a colon.
163163
tests/writer.textile+4−4
@@ -650,15 +650,15 @@ Here's an "inline link in pointy braces":/script?foo=1&bar=2.
650650
651651h2. Autolinks
652652
653−With an ampersand: "http://example.com/?foo=1&bar=2":http://example.com/?foo=1&bar=2
653+With an ampersand: "$":http://example.com/?foo=1&bar=2
654654
655655* In a list?
656−* "http://example.com/":http://example.com/
656+* "$":http://example.com/
657657* It should.
658658
659−An e-mail address: "nobody@nowhere.net":mailto:nobody@nowhere.net
659+An e-mail address: "<tt>nobody@nowhere.net</tt>":mailto:nobody@nowhere.net
660660
661−bq. Blockquoted: "http://example.com/":http://example.com/
661+bq. Blockquoted: "$":http://example.com/
662662
663663
664664