diff options
author | John MacFarlane <fiddlosopher@gmail.com> | 2013-06-19 08:56:11 -0700 |
---|---|---|
committer | John MacFarlane <fiddlosopher@gmail.com> | 2013-06-19 08:56:11 -0700 |
commit | e0832b0359628655d8bb6b84375bbd504d426aec (patch) | |
tree | 8e6d105a16270f19b8c4aa1003fab24fabc1eeb1 /src | |
parent | b04dfde403b4b43dbdf046f37c0b240e6f8af488 (diff) | |
download | pandoc-e0832b0359628655d8bb6b84375bbd504d426aec.tar.gz |
Markdown reader: fixed bug in unmatched reference links.
The input
[*infile*] [*outfile*]
was getting improperly parsed: "infile" was emphasized, but
"*outfile*" was literal. This was due to failure to parse the
"fallback" in the reference link parser.
Closes #883.
Diffstat (limited to 'src')
-rw-r--r-- | src/Text/Pandoc/Readers/Markdown.hs | 19 |
1 files changed, 12 insertions, 7 deletions
diff --git a/src/Text/Pandoc/Readers/Markdown.hs b/src/Text/Pandoc/Readers/Markdown.hs index 69011bc56..47b1cbbaa 100644 --- a/src/Text/Pandoc/Readers/Markdown.hs +++ b/src/Text/Pandoc/Readers/Markdown.hs @@ -1542,11 +1542,13 @@ regLink constructor lab = try $ do referenceLink :: (String -> String -> Inlines -> Inlines) -> (F Inlines, String) -> MarkdownParser (F Inlines) referenceLink constructor (lab, raw) = do - (ref,raw') <- try (optional (char ' ') >> - optional (newline >> skipSpaces) >> - reference) <|> return (mempty, "") + sp <- (True <$ lookAhead (char ' ')) <|> return False + (ref,raw') <- try + (skipSpaces >> optional (newline >> skipSpaces) >> reference) + <|> return (mempty, "") let labIsRef = raw' == "" || raw' == "[]" let key = toKey $ if labIsRef then raw else raw' + parsedRaw <- parseFromString (mconcat <$> many inline) raw' let dropRB (']':xs) = xs dropRB xs = xs let dropLB ('[':xs) = xs @@ -1560,13 +1562,16 @@ referenceLink constructor (lab, raw) = do case M.lookup key keys of Nothing -> do headers <- asksF stateHeaders - let ref' = runF (if labIsRef then lab else ref) defaultParserState - let makeFallback x = B.str "[" <> x <> B.str "]" <> B.str raw' + ref' <- if labIsRef then lab else ref + parsedRaw' <- parsedRaw + fallback' <- fallback + let fallback'' = B.str "[" <> fallback' <> B.str "]" <> + (if sp && not (null raw) then B.space else mempty) <> parsedRaw' if implicitHeaderRefs then case M.lookup ref' headers of Just ident -> constructor ('#':ident) "" <$> lab - Nothing -> makeFallback <$> fallback - else makeFallback <$> fallback + Nothing -> return fallback'' + else return fallback'' Just (src,tit) -> constructor src tit <$> lab bareURL :: MarkdownParser (F Inlines) |