git.iko.soy/typeable/pandoc
on master help sign in
Org reader: Fix cite parsing behaviour
bfd5c6bHerwig Stuetz
src/Text/Pandoc/Readers/Org/Inlines.hs+10−2
@@ -339,8 +339,16 @@ linkLikeOrgRefCite = try $ do
339-- | Read a citation key. The characters allowed in citation keys are taken
339-- | Read a citation key. The characters allowed in citation keys are taken
340-- from the `org-ref-cite-re` variable in `org-ref.el`.
340-- from the `org-ref-cite-re` variable in `org-ref.el`.
341orgRefCiteKey :: PandocMonad m => OrgParser m String
341orgRefCiteKey :: PandocMonad m => OrgParser m String
342−orgRefCiteKey = try . many1 . satisfy $ \c ->
342+orgRefCiteKey =
343− isAlphaNum c || c `elem` ("-_:\\./"::String)
343+ let citeKeySpecialChars = "-_:\\./," :: String
344+ isCiteKeySpecialChar c = c `elem` citeKeySpecialChars
345+ isCiteKeyChar c = isAlphaNum c || isCiteKeySpecialChar c
346+
347+ in try $ many1Till (satisfy $ isCiteKeyChar)
348+ $ try . lookAhead $ do
349+ many . satisfy $ isCiteKeySpecialChar
350+ satisfy $ not . isCiteKeyChar
351+
344
352
345-- | Supported citation types. Only a small subset of org-ref types is
353-- | Supported citation types. Only a small subset of org-ref types is
346-- supported for now. TODO: rewrite this, use LaTeX reader as template.
354-- supported for now. TODO: rewrite this, use LaTeX reader as template.
test/Tests/Readers/Org.hs+36
@@ -334,6 +334,18 @@ tests =
334 }
334 }
335 in (para $ cite [citation] "cite:pandoc")
335 in (para $ cite [citation] "cite:pandoc")
336
336
337+ , "Org-ref simple citation with underscores" =:
338+ "cite:pandoc_org_ref" =?>
339+ let citation = Citation
340+ { citationId = "pandoc_org_ref"
341+ , citationPrefix = mempty
342+ , citationSuffix = mempty
343+ , citationMode = AuthorInText
344+ , citationNoteNum = 0
345+ , citationHash = 0
346+ }
347+ in (para $ cite [citation] "cite:pandoc_org_ref")
348+
337 , "Org-ref simple citation succeeded by comma" =:
349 , "Org-ref simple citation succeeded by comma" =:
338 "cite:pandoc," =?>
350 "cite:pandoc," =?>
339 let citation = Citation
351 let citation = Citation
@@ -346,6 +358,30 @@ tests =
346 }
358 }
347 in (para $ cite [citation] "cite:pandoc" <> str ",")
359 in (para $ cite [citation] "cite:pandoc" <> str ",")
348
360
361+ , "Org-ref simple citation succeeded by dot" =:
362+ "cite:pandoc." =?>
363+ let citation = Citation
364+ { citationId = "pandoc"
365+ , citationPrefix = mempty
366+ , citationSuffix = mempty
367+ , citationMode = AuthorInText
368+ , citationNoteNum = 0
369+ , citationHash = 0
370+ }
371+ in (para $ cite [citation] "cite:pandoc" <> str ".")
372+
373+ , "Org-ref simple citation succeeded by colon" =:
374+ "cite:pandoc:" =?>
375+ let citation = Citation
376+ { citationId = "pandoc"
377+ , citationPrefix = mempty
378+ , citationSuffix = mempty
379+ , citationMode = AuthorInText
380+ , citationNoteNum = 0
381+ , citationHash = 0
382+ }
383+ in (para $ cite [citation] "cite:pandoc" <> str ":")
384+
349 , "Org-ref simple citep citation" =:
385 , "Org-ref simple citep citation" =:
350 "citep:pandoc" =?>
386 "citep:pandoc" =?>
351 let citation = Citation
387 let citation = Citation