git.iko.soy/typeable/pandoc
on master help sign in
Merge branch 'citations'
1a2eea2John MacFarlane
src/Text/Pandoc/Readers/Markdown.hs+14−8
@@ -1248,6 +1248,7 @@ inline = choice [ whitespace
1248 , emph
1248 , emph
1249 , note
1249 , note
1250 , cite
1250 , cite
1251+ , textCite
1251 , link
1252 , link
1252 , image
1253 , image
1253 , math
1254 , math
@@ -1630,12 +1631,12 @@ rawHtmlInline = do
1630cite :: MarkdownParser (F Inlines)
1631cite :: MarkdownParser (F Inlines)
1631cite = do
1632cite = do
1632 guardEnabled Ext_citations
1633 guardEnabled Ext_citations
1633− getOption readerReferences >>= guard . not . null
1634− citations <- textualCite <|> normalCite
1634+ citations <- normalCite
1635 return $ flip B.cite mempty <$> citations
1635 return $ flip B.cite mempty <$> citations
1636
1636
1637−textualCite :: MarkdownParser (F [Citation])
1637+textCite :: MarkdownParser (F Inlines)
1638−textualCite = try $ do
1638+textCite = try $ do
1639+ guardEnabled Ext_citations
1639 (_, key) <- citeKey
1640 (_, key) <- citeKey
1640 let first = Citation{ citationId = key
1641 let first = Citation{ citationId = key
1641 , citationPrefix = []
1642 , citationPrefix = []
@@ -1646,8 +1647,15 @@ textualCite = try $ do
1646 }
1647 }
1647 mbrest <- option Nothing $ try $ spnl >> Just <$> normalCite
1648 mbrest <- option Nothing $ try $ spnl >> Just <$> normalCite
1648 case mbrest of
1649 case mbrest of
1649− Just rest -> return $ (first:) <$> rest
1650+ Just rest -> return $ (flip B.cite mempty . (first:)) <$> rest
1650− Nothing -> option (return [first]) $ bareloc first
1651+ Nothing -> (do cites <- bareloc first
1652+ return $ flip B.cite mempty <$> cites)
1653+ <|> (do guardEnabled Ext_example_lists
1654+ st <- getState
1655+ case M.lookup key (stateExamples st) of
1656+ Just n -> return $ return $ B.str (show n)
1657+ Nothing -> mzero)
1658+ <|> (return $ return $ flip B.cite mempty [first])
1651
1659
1652bareloc :: Citation -> MarkdownParser (F [Citation])
1660bareloc :: Citation -> MarkdownParser (F [Citation])
1653bareloc c = try $ do
1661bareloc c = try $ do
@@ -1679,8 +1687,6 @@ citeKey = try $ do
1679 let internal p = try $ p >>~ lookAhead (letter <|> digit)
1687 let internal p = try $ p >>~ lookAhead (letter <|> digit)
1680 rest <- many $ letter <|> digit <|> internal (oneOf ":.#$%&-_?<>~/")
1688 rest <- many $ letter <|> digit <|> internal (oneOf ":.#$%&-_?<>~/")
1681 let key = first:rest
1689 let key = first:rest
1682− citations' <- map CSL.refId <$> getOption readerReferences
1683− guard $ key `elem` citations'
1684 return (suppress_author, key)
1690 return (suppress_author, key)
1685
1691
1686suffix :: MarkdownParser (F Inlines)
1692suffix :: MarkdownParser (F Inlines)
src/Text/Pandoc/Writers/Markdown.hs+3−1
@@ -614,7 +614,9 @@ inlineToMarkdown opts (LineBreak)
614 | otherwise = return $ " " <> cr
614 | otherwise = return $ " " <> cr
615inlineToMarkdown _ Space = return space
615inlineToMarkdown _ Space = return space
616inlineToMarkdown opts (Cite (c:cs) lst)
616inlineToMarkdown opts (Cite (c:cs) lst)
617+ | writerCiteMethod opts == Citeproc && not (null lst) &&
618+ case lst of { RawInline "latex" _ : _ -> False; _ -> True} =
617− | writerCiteMethod opts == Citeproc = inlineListToMarkdown opts lst
619+ inlineListToMarkdown opts lst
618 | citationMode c == AuthorInText = do
620 | citationMode c == AuthorInText = do
619 suffs <- inlineListToMarkdown opts $ citationSuffix c
621 suffs <- inlineListToMarkdown opts $ citationSuffix c
620 rest <- mapM convertOne cs
622 rest <- mapM convertOne cs