Markdown: allow ---- in angle-bracket autolinks.

The uri parser is designed for bare URIs.  In angle-bracket contexts,
we can be sure that we don't have trailing punctuation.  So
`<http://openclipart.org/detail/22566/lego-smiley----happy-by-pitr>`
should work now.

Closes #768.
This commit is contained in:
John MacFarlane 2013-02-28 22:05:22 -08:00
parent abdaa96b03
commit 649608d324

View file

@ -41,6 +41,7 @@ import qualified Text.Pandoc.Builder as B
import Text.Pandoc.Builder (Inlines, Blocks, trimInlines, (<>)) import Text.Pandoc.Builder (Inlines, Blocks, trimInlines, (<>))
import Text.Pandoc.Options import Text.Pandoc.Options
import Text.Pandoc.Shared import Text.Pandoc.Shared
import Text.Pandoc.XML (fromEntities)
import Text.Pandoc.Parsing hiding (tableWith) import Text.Pandoc.Parsing hiding (tableWith)
import Text.Pandoc.Readers.LaTeX ( rawLaTeXInline, rawLaTeXBlock ) import Text.Pandoc.Readers.LaTeX ( rawLaTeXInline, rawLaTeXBlock )
import Text.Pandoc.Readers.HTML ( htmlTag, htmlInBalanced, isInlineTag, isBlockTag, import Text.Pandoc.Readers.HTML ( htmlTag, htmlInBalanced, isInlineTag, isBlockTag,
@ -1565,8 +1566,12 @@ autoLink :: MarkdownParser (F Inlines)
autoLink = try $ do autoLink = try $ do
char '<' char '<'
(orig, src) <- uri <|> emailAddress (orig, src) <- uri <|> emailAddress
char '>' -- in rare cases, something may remain after the uri parser
return $ return $ B.link src "" (B.str orig) -- is finished, because the uri parser tries to avoid parsing
-- final punctuation. for example: in `<http://hi---there>`,
-- the URI parser will stop before the dashes.
extra <- fromEntities <$> manyTill nonspaceChar (char '>')
return $ return $ B.link (src ++ escapeURI extra) "" (B.str $ orig ++ extra)
image :: MarkdownParser (F Inlines) image :: MarkdownParser (F Inlines)
image = try $ do image = try $ do