Merge branch 'citations'
This commit is contained in:
commit
1a2eea23a1
2 changed files with 17 additions and 9 deletions
|
@ -1248,6 +1248,7 @@ inline = choice [ whitespace
|
||||||
, emph
|
, emph
|
||||||
, note
|
, note
|
||||||
, cite
|
, cite
|
||||||
|
, textCite
|
||||||
, link
|
, link
|
||||||
, image
|
, image
|
||||||
, math
|
, math
|
||||||
|
@ -1630,12 +1631,12 @@ rawHtmlInline = do
|
||||||
cite :: MarkdownParser (F Inlines)
|
cite :: MarkdownParser (F Inlines)
|
||||||
cite = do
|
cite = do
|
||||||
guardEnabled Ext_citations
|
guardEnabled Ext_citations
|
||||||
getOption readerReferences >>= guard . not . null
|
citations <- normalCite
|
||||||
citations <- textualCite <|> normalCite
|
|
||||||
return $ flip B.cite mempty <$> citations
|
return $ flip B.cite mempty <$> citations
|
||||||
|
|
||||||
textualCite :: MarkdownParser (F [Citation])
|
textCite :: MarkdownParser (F Inlines)
|
||||||
textualCite = try $ do
|
textCite = try $ do
|
||||||
|
guardEnabled Ext_citations
|
||||||
(_, key) <- citeKey
|
(_, key) <- citeKey
|
||||||
let first = Citation{ citationId = key
|
let first = Citation{ citationId = key
|
||||||
, citationPrefix = []
|
, citationPrefix = []
|
||||||
|
@ -1646,8 +1647,15 @@ textualCite = try $ do
|
||||||
}
|
}
|
||||||
mbrest <- option Nothing $ try $ spnl >> Just <$> normalCite
|
mbrest <- option Nothing $ try $ spnl >> Just <$> normalCite
|
||||||
case mbrest of
|
case mbrest of
|
||||||
Just rest -> return $ (first:) <$> rest
|
Just rest -> return $ (flip B.cite mempty . (first:)) <$> rest
|
||||||
Nothing -> option (return [first]) $ bareloc first
|
Nothing -> (do cites <- bareloc first
|
||||||
|
return $ flip B.cite mempty <$> cites)
|
||||||
|
<|> (do guardEnabled Ext_example_lists
|
||||||
|
st <- getState
|
||||||
|
case M.lookup key (stateExamples st) of
|
||||||
|
Just n -> return $ return $ B.str (show n)
|
||||||
|
Nothing -> mzero)
|
||||||
|
<|> (return $ return $ flip B.cite mempty [first])
|
||||||
|
|
||||||
bareloc :: Citation -> MarkdownParser (F [Citation])
|
bareloc :: Citation -> MarkdownParser (F [Citation])
|
||||||
bareloc c = try $ do
|
bareloc c = try $ do
|
||||||
|
@ -1679,8 +1687,6 @@ citeKey = try $ do
|
||||||
let internal p = try $ p >>~ lookAhead (letter <|> digit)
|
let internal p = try $ p >>~ lookAhead (letter <|> digit)
|
||||||
rest <- many $ letter <|> digit <|> internal (oneOf ":.#$%&-_?<>~/")
|
rest <- many $ letter <|> digit <|> internal (oneOf ":.#$%&-_?<>~/")
|
||||||
let key = first:rest
|
let key = first:rest
|
||||||
citations' <- map CSL.refId <$> getOption readerReferences
|
|
||||||
guard $ key `elem` citations'
|
|
||||||
return (suppress_author, key)
|
return (suppress_author, key)
|
||||||
|
|
||||||
suffix :: MarkdownParser (F Inlines)
|
suffix :: MarkdownParser (F Inlines)
|
||||||
|
|
|
@ -614,7 +614,9 @@ inlineToMarkdown opts (LineBreak)
|
||||||
| otherwise = return $ " " <> cr
|
| otherwise = return $ " " <> cr
|
||||||
inlineToMarkdown _ Space = return space
|
inlineToMarkdown _ Space = return space
|
||||||
inlineToMarkdown opts (Cite (c:cs) lst)
|
inlineToMarkdown opts (Cite (c:cs) lst)
|
||||||
| writerCiteMethod opts == Citeproc = inlineListToMarkdown opts lst
|
| writerCiteMethod opts == Citeproc && not (null lst) &&
|
||||||
|
case lst of { RawInline "latex" _ : _ -> False; _ -> True} =
|
||||||
|
inlineListToMarkdown opts lst
|
||||||
| citationMode c == AuthorInText = do
|
| citationMode c == AuthorInText = do
|
||||||
suffs <- inlineListToMarkdown opts $ citationSuffix c
|
suffs <- inlineListToMarkdown opts $ citationSuffix c
|
||||||
rest <- mapM convertOne cs
|
rest <- mapM convertOne cs
|
||||||
|
|
Loading…
Reference in a new issue