git.iko.soy/typeable/pandoc
on master help sign in
Improve emailAddress in Text.Pandoc.Parsing.
0352f78John MacFarlane
src/Text/Pandoc/Parsing.hs+3−4
@@ -693,13 +693,12 @@ emailAddress = try $ toResult <$> mailbox <*> (char '@' *> domain)
693 mailbox = intercalate "." <$> (emailWord `sepBy1'` dot)
693 mailbox = intercalate "." <$> (emailWord `sepBy1'` dot)
694 domain = intercalate "." <$> (subdomain `sepBy1'` dot)
694 domain = intercalate "." <$> (subdomain `sepBy1'` dot)
695 dot = char '.'
695 dot = char '.'
696− subdomain = many1 $ alphaNum <|> innerPunct
696+ subdomain = many1 $ alphaNum <|> innerPunct (=='-')
697 -- this excludes some valid email addresses, since an
697 -- this excludes some valid email addresses, since an
698 -- email could contain e.g. '__', but gives better results
698 -- email could contain e.g. '__', but gives better results
699 -- for our purposes, when combined with markdown parsing:
699 -- for our purposes, when combined with markdown parsing:
700− innerPunct = try (satisfy (\c -> isEmailPunct c || c == '@')
700+ innerPunct f = try (satisfy f
701− <* notFollowedBy space
701+ <* notFollowedBy (satisfy (not . isAlphaNum)))
702− <* notFollowedBy (satisfy isPunctuation))
703 -- technically an email address could begin with a symbol,
702 -- technically an email address could begin with a symbol,
704 -- but allowing this creates too many problems.
703 -- but allowing this creates too many problems.
705 -- See e.g. https://github.com/jgm/pandoc/issues/2940
704 -- See e.g. https://github.com/jgm/pandoc/issues/2940
src/Text/Pandoc/Readers/Txt2Tags.hs+21−1
@@ -478,9 +478,29 @@ macro = try $ do
478-- raw URLs in text are automatically linked
478-- raw URLs in text are automatically linked
479url :: T2T Inlines
479url :: T2T Inlines
480url = try $ do
480url = try $ do
481− (rawUrl, escapedUrl) <- try uri <|> emailAddress
481+ (rawUrl, escapedUrl) <- try uri <|> emailAddress'
482 return $ B.link rawUrl "" (B.str escapedUrl)
482 return $ B.link rawUrl "" (B.str escapedUrl)
483
483
484+emailAddress' :: T2T (Text, Text)
485+emailAddress' = do
486+ (base, mailURI) <- emailAddress
487+ query <- option "" emailQuery
488+ return (base <> query, mailURI <> query)
489+
490+emailQuery :: T2T Text
491+emailQuery = do
492+ char '?'
493+ parts <- kv `sepBy1` (char '&')
494+ return $ "?" <> T.intercalate "&" parts
495+
496+kv :: T2T Text
497+kv = do
498+ k <- T.pack <$> many1 alphaNum
499+ char '='
500+ let vchar = alphaNum <|> try (oneOf "%._/~:,=$@&+-;*" <* lookAhead alphaNum)
501+ v <- T.pack <$> many1 vchar
502+ return (k <> "=" <> v)
503+
484uri :: T2T (Text, Text)
504uri :: T2T (Text, Text)
485uri = try $ do
505uri = try $ do
486 address <- t2tURI
506 address <- t2tURI