Merge pull request #2090 from lierdakil/issue2083

Fix for #2083 (citation suffix clashes with links and footnotes)
This commit is contained in:
John MacFarlane 2015-04-19 16:49:34 -07:00
commit 5b5813c30b
2 changed files with 57 additions and 2 deletions

View file

@ -1887,8 +1887,20 @@ textualCite = try $ do
return $ (flip B.cite (B.text $ '@':key ++ " " ++ raw) . (first:))
<$> rest
Nothing ->
(do (cs, raw) <- withRaw $ bareloc first
return $ (flip B.cite (B.text $ '@':key ++ " " ++ raw)) <$> cs)
(do
(cs, raw) <- withRaw $ bareloc first
let (spaces',raw') = span isSpace raw
spc | null spaces' = mempty
| otherwise = B.space
lab <- parseFromString (mconcat <$> many inline) $ dropBrackets raw'
fallback <- referenceLink B.link (lab,raw')
return $ do
fallback' <- fallback
cs' <- cs
return $
case B.toList fallback' of
Link{}:_ -> B.cite [first] (B.str $ '@':key) <> spc <> fallback'
_ -> B.cite cs' (B.text $ '@':key ++ " " ++ raw))
<|> return (do st <- askF
return $ case M.lookup key (stateExamples st) of
Just n -> B.str (show n)
@ -1898,10 +1910,12 @@ bareloc :: Citation -> MarkdownParser (F [Citation])
bareloc c = try $ do
spnl
char '['
notFollowedBy $ char '^'
suff <- suffix
rest <- option (return []) $ try $ char ';' >> citeList
spnl
char ']'
notFollowedBy $ oneOf "[("
return $ do
suff' <- suff
rest' <- rest

View file

@ -324,4 +324,45 @@ tests = [ testGroup "inline code"
}
] "@1657:huyghens")
]
, let citation = cite [Citation "cita" [] [] AuthorInText 0 0] (str "@cita")
in testGroup "footnote/link following citation" -- issue #2083
[ "footnote" =:
unlines [ "@cita[^note]"
, ""
, "[^note]: note" ] =?>
para (
citation <> note (para $ str "note")
)
, "normal link" =:
"@cita [link](http://www.com)" =?>
para (
citation <> space <> link "http://www.com" "" (str "link")
)
, "reference link" =:
unlines [ "@cita [link][link]"
, ""
, "[link]: http://www.com" ] =?>
para (
citation <> space <> link "http://www.com" "" (str "link")
)
, "short reference link" =:
unlines [ "@cita [link]"
, ""
, "[link]: http://www.com" ] =?>
para (
citation <> space <> link "http://www.com" "" (str "link")
)
, "implicit header link" =:
unlines [ "# Header"
, "@cita [Header]" ] =?>
headerWith ("header",[],[]) 1 (str "Header") <> para (
citation <> space <> link "#header" "" (str "Header")
)
, "regular citation" =:
"@cita [foo]" =?>
para (
cite [Citation "cita" [] [Str "foo"] AuthorInText 0 0]
(str "@cita" <> space <> str "[foo]")
)
]
]