Changed Ext_autolink_urls -> Ext_autolink_bare_uris.

Added tests.
This commit is contained in:
John MacFarlane 2013-01-15 12:44:50 -08:00
parent e9b3d5aa7a
commit bf3a911a1c
5 changed files with 11 additions and 8 deletions

4
README
View file

@ -2342,8 +2342,8 @@ Note that the pandoc document model does not support
abbreviations, so if this extension is enabled, abbreviation keys are
simply skipped (as opposed to being parsed as paragraphs).
**Extension: `autolink_urls`**\
Makes all absolute URLs into links, even when not surrounded by
**Extension: `autolink_bare_uris`**\
Makes all absolute URIs into links, even when not surrounded by
pointy braces `<...>`.
Producing slide shows with Pandoc

View file

@ -76,7 +76,7 @@ data Extension =
| Ext_markdown_attribute -- ^ Interpret text inside HTML as markdown
-- iff container has attribute 'markdown'
| Ext_escaped_line_breaks -- ^ Treat a backslash at EOL as linebreak
| Ext_autolink_urls -- ^ Make all absolute URLs into links
| Ext_autolink_bare_uris -- ^ Make all absolute URIs into links
| Ext_fancy_lists -- ^ Enable fancy list numbers and delimiters
| Ext_startnum -- ^ Make start number of ordered list significant
| Ext_definition_lists -- ^ Definition lists as in pandoc, mmd, php
@ -159,7 +159,7 @@ githubMarkdownExtensions = Set.fromList
, Ext_fenced_code_blocks
, Ext_fenced_code_attributes
, Ext_backtick_code_blocks
, Ext_autolink_urls
, Ext_autolink_bare_uris
, Ext_intraword_underscores
, Ext_strikeout
, Ext_hard_line_breaks

View file

@ -212,7 +212,7 @@ notFollowedBy' p = try $ join $ do a <- try p
-- (This version due to Andrew Pimlott on the Haskell mailing list.)
oneOfStrings' :: (Char -> Char -> Bool) -> [String] -> Parser [Char] st String
oneOfStrings' matches [] = fail "no strings"
oneOfStrings' _ [] = fail "no strings"
oneOfStrings' matches strs = try $ do
c <- anyChar
let strs' = [xs | (x:xs) <- strs, x `matches` c]
@ -392,10 +392,13 @@ schemes = ["coap","doi","javascript","aaa","aaas","about","acap","cap","cid",
"ventrilo","view-source","webcal","wtai","wyciwyg","xfire","xri",
"ymsgr"]
uriScheme :: Parser [Char] st String
uriScheme = oneOfStringsCI schemes
-- | Parses a URI. Returns pair of original and URI-escaped version.
uri :: Parser [Char] st (String, String)
uri = try $ do
scheme <- oneOfStringsCI schemes
scheme <- uriScheme
char ':'
-- /^[\/\w\u0080-\uffff]+|%[A-Fa-f0-9]+|&#?\w+;|(?:[,]+|[\S])[%&~\w\u0080-\uffff]/
-- We allow punctuation except at the end, since

View file

@ -1543,7 +1543,7 @@ referenceLink constructor (lab, raw) = do
bareURL :: MarkdownParser (F Inlines)
bareURL = try $ do
guardEnabled Ext_autolink_urls
guardEnabled Ext_autolink_bare_uris
(orig, src) <- uri <|> emailAddress
return $ return $ B.link src "" (B.str orig)

View file

@ -24,7 +24,7 @@ infix 4 =:
testBareLink :: (String, Inlines) -> Test
testBareLink (inp, ils) =
test (readMarkdown def{ readerExtensions =
Set.fromList [Ext_autolink_urls] })
Set.fromList [Ext_autolink_bare_uris] })
inp (inp, doc $ para ils)
autolink :: String -> Inlines