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
This commit is contained in:
parent
4aa3e1f978
commit
4cd573c61f
6 changed files with 16 additions and 19 deletions
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -1 +1 @@
|
|||
Subproject commit 4c1f840c392010309cdb4cc1b8db4f4b24ff6424
|
||||
Subproject commit 1e32f282085c31720c3f0adfed37076d890f2bff
|
|
@ -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"]
|
||||
|
|
|
@ -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.
|
||||
|
||||
|
|
|
@ -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/
|
||||
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue