diff options
author | John MacFarlane <jgm@berkeley.edu> | 2012-11-06 16:05:17 -0800 |
---|---|---|
committer | John MacFarlane <jgm@berkeley.edu> | 2012-11-06 16:05:17 -0800 |
commit | 4cd573c61f61885cb368b40dccd1b458c39846c7 (patch) | |
tree | c8fe5e6d7429b1d14fbe6b6ae1bfcd797b8fe626 | |
parent | 4aa3e1f978fc285d16f047c800504b03cc897ec8 (diff) | |
download | pandoc-4cd573c61f61885cb368b40dccd1b458c39846c7.tar.gz |
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
-rw-r--r-- | src/Text/Pandoc/Readers/Textile.hs | 16 | ||||
-rw-r--r-- | src/Text/Pandoc/Writers/Textile.hs | 5 | ||||
m--------- | templates | 13 | ||||
-rw-r--r-- | tests/textile-reader.native | 2 | ||||
-rw-r--r-- | tests/textile-reader.textile | 2 | ||||
-rw-r--r-- | tests/writer.textile | 8 |
6 files changed, 23 insertions, 23 deletions
diff --git a/src/Text/Pandoc/Readers/Textile.hs b/src/Text/Pandoc/Readers/Textile.hs index c6a2938a9..f2a70612d 100644 --- a/src/Text/Pandoc/Readers/Textile.hs +++ b/src/Text/Pandoc/Readers/Textile.hs @@ -46,7 +46,6 @@ Left to be implemented: - continued blocks (ex bq..) TODO : refactor common patterns across readers : - - autolink - more ... -} @@ -361,8 +360,7 @@ inline = choice inlineParsers <?> "inline" -- | Inline parsers tried in order inlineParsers :: [Parser [Char] ParserState Inline] -inlineParsers = [ autoLink - , str +inlineParsers = [ str , whitespace , endline , code @@ -501,7 +499,8 @@ linkNoB = try $ do char ':' let stopChars = "!.,;:" url <- manyTill nonspaceChar (lookAhead $ space <|> try (oneOf stopChars >> (space <|> newline))) - return $ Link name (url, "") + let name' = if name == [Str "$"] then [Str url] else name + return $ Link name' (url, "") linkB :: Parser [Char] ParserState Inline linkB = try $ do @@ -509,13 +508,8 @@ linkB = try $ do name <- surrounded (char '"') inline char ':' url <- manyTill nonspaceChar (char ']') - return $ Link name (url, "") - --- | Detect plain links to http or email. -autoLink :: Parser [Char] ParserState Inline -autoLink = do - (orig, src) <- (try uri <|> try emailAddress) - return $ Link [Str orig] (src, "") + let name' = if name == [Str "$"] then [Str url] else name + return $ Link name' (url, "") -- | image embedding image :: Parser [Char] ParserState Inline diff --git a/src/Text/Pandoc/Writers/Textile.hs b/src/Text/Pandoc/Writers/Textile.hs index 5f3bb6bcd..44fdc7efb 100644 --- a/src/Text/Pandoc/Writers/Textile.hs +++ b/src/Text/Pandoc/Writers/Textile.hs @@ -396,7 +396,10 @@ inlineToTextile _ Space = return " " inlineToTextile opts (Link txt (src, _)) = do label <- case txt of - [Code _ s] -> return s + [Code _ s] + | s == src -> return "$" + [Str s] + | s == src -> return "$" _ -> inlineListToTextile opts txt return $ "\"" ++ label ++ "\":" ++ src diff --git a/templates b/templates -Subproject 4c1f840c392010309cdb4cc1b8db4f4b24ff642 +Subproject 1e32f282085c31720c3f0adfed37076d890f2bf diff --git a/tests/textile-reader.native b/tests/textile-reader.native index 4002ad557..575aefdf9 100644 --- a/tests/textile-reader.native +++ b/tests/textile-reader.native @@ -85,7 +85,7 @@ Pandoc (Meta {docTitle = [], docAuthors = [], docDate = []}) ,Header 2 [Str "Explicit"] ,Para [Str "Just",Space,Str "a",Space,Link [Str "url"] ("http://www.url.com","")] ,Para [Link [Str "Email",Space,Str "link"] ("mailto:nobody@nowhere.net","")] -,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 "."] +,Para [Str "Automatic",Space,Str "linking",Space,Str "to",Space,Link [Str "http://www.example.com"] ("http://www.example.com",""),Str "."] ,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 "."] ,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 "."] ,Header 1 [Str "Tables"] diff --git a/tests/textile-reader.textile b/tests/textile-reader.textile index a096ded1d..067cf690a 100644 --- a/tests/textile-reader.textile +++ b/tests/textile-reader.textile @@ -157,7 +157,7 @@ Just a "url":http://www.url.com "Email link":mailto:nobody@nowhere.net -Automatic linking to http://www.example.com and foobar@example.com. +Automatic linking to "$":http://www.example.com. "Example":http://www.example.com/: Example of a link followed by a colon. diff --git a/tests/writer.textile b/tests/writer.textile index 51aca5a08..ace6d8763 100644 --- a/tests/writer.textile +++ b/tests/writer.textile @@ -650,15 +650,15 @@ Here's an "inline link in pointy braces":/script?foo=1&bar=2. h2. Autolinks -With an ampersand: "http://example.com/?foo=1&bar=2":http://example.com/?foo=1&bar=2 +With an ampersand: "$":http://example.com/?foo=1&bar=2 * In a list? -* "http://example.com/":http://example.com/ +* "$":http://example.com/ * It should. -An e-mail address: "nobody@nowhere.net":mailto:nobody@nowhere.net +An e-mail address: "<tt>nobody@nowhere.net</tt>":mailto:nobody@nowhere.net -bq. Blockquoted: "http://example.com/":http://example.com/ +bq. Blockquoted: "$":http://example.com/ |