Org reader: Fix cite parsing behaviour

Until now, org-ref cite keys included special characters also at the
end. This caused problems when citations occur right before colons or
at the end of a sentence.

With this change, all non alphanumeric characters at the end of a cite
key are ignored.

This also adds `,` to the list of special characters that are legal
in cite keys to better mirror the behaviour of org-export.
This commit is contained in:
Herwig Stuetz 2017-05-23 21:30:31 +02:00
parent 5a71632d11
commit bfd5c6b172
2 changed files with 46 additions and 2 deletions

View file

@ -339,8 +339,16 @@ linkLikeOrgRefCite = try $ do
-- | Read a citation key. The characters allowed in citation keys are taken
-- from the `org-ref-cite-re` variable in `org-ref.el`.
orgRefCiteKey :: PandocMonad m => OrgParser m String
orgRefCiteKey = try . many1 . satisfy $ \c ->
isAlphaNum c || c `elem` ("-_:\\./"::String)
orgRefCiteKey =
let citeKeySpecialChars = "-_:\\./," :: String
isCiteKeySpecialChar c = c `elem` citeKeySpecialChars
isCiteKeyChar c = isAlphaNum c || isCiteKeySpecialChar c
in try $ many1Till (satisfy $ isCiteKeyChar)
$ try . lookAhead $ do
many . satisfy $ isCiteKeySpecialChar
satisfy $ not . isCiteKeyChar
-- | Supported citation types. Only a small subset of org-ref types is
-- supported for now. TODO: rewrite this, use LaTeX reader as template.

View file

@ -334,6 +334,18 @@ tests =
}
in (para $ cite [citation] "cite:pandoc")
, "Org-ref simple citation with underscores" =:
"cite:pandoc_org_ref" =?>
let citation = Citation
{ citationId = "pandoc_org_ref"
, citationPrefix = mempty
, citationSuffix = mempty
, citationMode = AuthorInText
, citationNoteNum = 0
, citationHash = 0
}
in (para $ cite [citation] "cite:pandoc_org_ref")
, "Org-ref simple citation succeeded by comma" =:
"cite:pandoc," =?>
let citation = Citation
@ -346,6 +358,30 @@ tests =
}
in (para $ cite [citation] "cite:pandoc" <> str ",")
, "Org-ref simple citation succeeded by dot" =:
"cite:pandoc." =?>
let citation = Citation
{ citationId = "pandoc"
, citationPrefix = mempty
, citationSuffix = mempty
, citationMode = AuthorInText
, citationNoteNum = 0
, citationHash = 0
}
in (para $ cite [citation] "cite:pandoc" <> str ".")
, "Org-ref simple citation succeeded by colon" =:
"cite:pandoc:" =?>
let citation = Citation
{ citationId = "pandoc"
, citationPrefix = mempty
, citationSuffix = mempty
, citationMode = AuthorInText
, citationNoteNum = 0
, citationHash = 0
}
in (para $ cite [citation] "cite:pandoc" <> str ":")
, "Org-ref simple citep citation" =:
"citep:pandoc" =?>
let citation = Citation