git.iko.soy/typeable/pandoc
on master help sign in
Merge pull request #3699 from herwigstuetz/org-ref-cites
345bf8bJohn MacFarlane
src/Text/Pandoc/Parsing.hs+3−2
@@ -274,11 +274,12 @@ indentWith num = do
274 , try (char '\t' >> indentWith (num - tabStop)) ]
274 , try (char '\t' >> indentWith (num - tabStop)) ]
275
275
276-- | Like @manyTill@, but reads at least one item.
276-- | Like @manyTill@, but reads at least one item.
277−many1Till :: Stream s m t
277+many1Till :: (Show end, Stream s m t)
278 => ParserT s st m a
278 => ParserT s st m a
279 -> ParserT s st m end
279 -> ParserT s st m end
280 -> ParserT s st m [a]
280 -> ParserT s st m [a]
281many1Till p end = do
281many1Till p end = do
282+ notFollowedBy' end
282 first <- p
283 first <- p
283 rest <- manyTill p end
284 rest <- manyTill p end
284 return (first:rest)
285 return (first:rest)
@@ -343,7 +344,7 @@ blanklines :: Stream s m Char => ParserT s st m [Char]
343blanklines = many1 blankline
344blanklines = many1 blankline
344
345
345-- | Parses material enclosed between start and end parsers.
346-- | Parses material enclosed between start and end parsers.
346−enclosed :: Stream s m Char => ParserT s st m t -- ^ start parser
347+enclosed :: (Show end, Stream s m Char) => ParserT s st m t -- ^ start parser
347 -> ParserT s st m end -- ^ end parser
348 -> ParserT s st m end -- ^ end parser
348 -> ParserT s st m a -- ^ content parser (to be used repeatedly)
349 -> ParserT s st m a -- ^ content parser (to be used repeatedly)
349 -> ParserT s st m [a]
350 -> ParserT s st m [a]
src/Text/Pandoc/Readers/Org/Inlines.hs+12−4
@@ -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.
@@ -687,13 +695,13 @@ mathEnd c = try $ do
687 return res
695 return res
688
696
689
697
690−enclosedInlines :: PandocMonad m => OrgParser m a
698+enclosedInlines :: (PandocMonad m, Show b) => OrgParser m a
691 -> OrgParser m b
699 -> OrgParser m b
692 -> OrgParser m (F Inlines)
700 -> OrgParser m (F Inlines)
693enclosedInlines start end = try $
701enclosedInlines start end = try $
694 trimInlinesF . mconcat <$> enclosed start end inline
702 trimInlinesF . mconcat <$> enclosed start end inline
695
703
696−enclosedRaw :: PandocMonad m => OrgParser m a
704+enclosedRaw :: (PandocMonad m, Show b) => OrgParser m a
697 -> OrgParser m b
705 -> OrgParser m b
698 -> OrgParser m String
706 -> OrgParser m String
699enclosedRaw start end = try $
707enclosedRaw start end = try $
src/Text/Pandoc/Readers/TWiki.hs+2−2
@@ -349,13 +349,13 @@ linebreak = newline >> notFollowedBy newline >> (lastNewline <|> innerNewline)
349 where lastNewline = eof >> return mempty
349 where lastNewline = eof >> return mempty
350 innerNewline = return B.space
350 innerNewline = return B.space
351
351
352−between :: (Monoid c, PandocMonad m)
352+between :: (Monoid c, PandocMonad m, Show b)
353 => TWParser m a -> TWParser m b -> (TWParser m b -> TWParser m c)
353 => TWParser m a -> TWParser m b -> (TWParser m b -> TWParser m c)
354 -> TWParser m c
354 -> TWParser m c
355between start end p =
355between start end p =
356 mconcat <$> try (start >> notFollowedBy whitespace >> many1Till (p end) end)
356 mconcat <$> try (start >> notFollowedBy whitespace >> many1Till (p end) end)
357
357
358−enclosed :: (Monoid b, PandocMonad m)
358+enclosed :: (Monoid b, PandocMonad m, Show a)
359 => TWParser m a -> (TWParser m a -> TWParser m b) -> TWParser m b
359 => TWParser m a -> (TWParser m a -> TWParser m b) -> TWParser m b
360enclosed sep p = between sep (try $ sep <* endMarker) p
360enclosed sep p = between sep (try $ sep <* endMarker) p
361 where
361 where
src/Text/Pandoc/Readers/Textile.hs+1−1
@@ -692,7 +692,7 @@ langAttr = do
692 return $ \(id',classes,keyvals) -> (id',classes,("lang",lang):keyvals)
692 return $ \(id',classes,keyvals) -> (id',classes,("lang",lang):keyvals)
693
693
694-- | Parses material surrounded by a parser.
694-- | Parses material surrounded by a parser.
695−surrounded :: PandocMonad m
695+surrounded :: (PandocMonad m, Show t)
696 => ParserT [Char] st m t -- ^ surrounding parser
696 => ParserT [Char] st m t -- ^ surrounding parser
697 -> ParserT [Char] st m a -- ^ content parser (to be used repeatedly)
697 -> ParserT [Char] st m a -- ^ content parser (to be used repeatedly)
698 -> ParserT [Char] st m [a]
698 -> ParserT [Char] st m [a]
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