aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn MacFarlane <jgm@berkeley.edu>2021-08-17 15:34:23 -0700
committerJohn MacFarlane <jgm@berkeley.edu>2021-08-17 15:34:23 -0700
commitfd99fe4d7ee5459d32505ef14f4453839cfcefab (patch)
treeead3b17c09e1ed917e50f20bbf8e8faf4b6d8337
parent10dfd81000160f2b48bf9fe47ce4e6441bc1db52 (diff)
downloadpandoc-fd99fe4d7ee5459d32505ef14f4453839cfcefab.tar.gz
Revise citeproc code to fit new citeproc 0.5 API.
Linkification of URLs in the bibliography is now done in the citeproc library, depending on the setting of an option. We set that option depending on the value of the metadata field `link-bibliography` (defaulting to true, for consistency with earlier behavior, though the new behavior includes the CSL draft recommendation of hyperlinking the title or the whole entry if a DOI, PMID, PMCID, or URL field is present but not explicitly rendered). These changes implement the following recommendations from the draft CSL v1.0.2 spec (Appendix VI): > The CSL syntax does not have support for configuration of links. > However, processors should include links on bibliographic references, > using the following rules: > If the bibliography entry for an item renders any of the following > identifiers, the identifier should be anchored as a link, with the > target of the link as follows: > - url: output as is > - doi: prepend with "`https://doi.org/`" > - pmid: prepend with "`https://www.ncbi.nlm.nih.gov/pubmed/`" > - pmcid: prepend with "`https://www.ncbi.nlm.nih.gov/pmc/articles/`" > If the identifier is rendered as a URI, include rendered URI components > (e.g. "`https://doi.org/`") in the link anchor. Do not include any other > affix text in the link anchor (e.g. "Available from: ", "doi: ", "PMID: "). > If the bibliography entry for an item does not render any of > the above identifiers, then set the anchor of the link as the item > title. If title is not rendered, then set the anchor of the link as the > full bibliography entry for the item. Set the target of the link as one > of the following, in order of priority: > > - doi: prepend with "`https://doi.org/`" > - pmcid: prepend with "`https://www.ncbi.nlm.nih.gov/pmc/articles/`" > - pmid: prepend with "`https://www.ncbi.nlm.nih.gov/pubmed/`" > - url: output as is > > If the item data does not include any of the above identifiers, do not > include a link. > > Citation processors should include an option flag for calling > applications to disable bibliography linking behavior. Thanks to Benjamin Bray for getting this all working.
-rw-r--r--src/Text/Pandoc/Citeproc.hs43
-rw-r--r--src/Text/Pandoc/Citeproc/CslJson.hs1
-rw-r--r--src/Text/Pandoc/Writers/Powerpoint/Output.hs12
-rw-r--r--test/command/pandoc-citeproc-31.md5
-rw-r--r--test/command/pandoc-citeproc-327.md4
-rw-r--r--test/command/pandoc-citeproc-338.md3
-rw-r--r--test/command/pandoc-citeproc-386.md4
7 files changed, 21 insertions, 51 deletions
diff --git a/src/Text/Pandoc/Citeproc.hs b/src/Text/Pandoc/Citeproc.hs
index 39760776d..9a649402e 100644
--- a/src/Text/Pandoc/Citeproc.hs
+++ b/src/Text/Pandoc/Citeproc.hs
@@ -73,7 +73,9 @@ processCitations (Pandoc meta bs) = do
let linkCites = maybe False truish $ lookupMeta "link-citations" meta
- let opts = defaultCiteprocOptions{ linkCitations = linkCites }
+ let linkBib = maybe True truish $ lookupMeta "link-bibliography" meta
+ let opts = defaultCiteprocOptions{ linkCitations = linkCites
+ , linkBibliography = linkBib }
let result = Citeproc.citeproc opts style mblang refs citations
mapM_ (report . CiteprocWarning) (resultWarnings result)
let sopts = styleOptions style
@@ -105,8 +107,7 @@ processCitations (Pandoc meta bs) = do
$ cits
return $ walk removeQuoteSpan
$ Pandoc meta''
- $ insertRefs refkvs classes meta''
- (walk fixLinks $ B.toList bibs) bs'
+ $ insertRefs refkvs classes meta'' (B.toList bibs) bs'
removeQuoteSpan :: Inline -> Inline
removeQuoteSpan (Span ("",["csl-quoted"],[]) xs) = Span nullAttr xs
@@ -210,7 +211,7 @@ getReferences mblocale (Pandoc meta bs) = do
Nothing -> return []
let addQuoteSpan (Quoted _ xs) = Span ("",["csl-quoted"],[]) xs
addQuoteSpan x = x
- return $ map (linkifyVariables . legacyDateRanges . walk addQuoteSpan)
+ return $ map (legacyDateRanges . walk addQuoteSpan)
(externalRefs ++ inlineRefs)
-- note that inlineRefs can override externalRefs
@@ -278,7 +279,7 @@ insertResolvedCitations (Cite cs ils) = do
[] -> return (Cite cs ils)
(x:xs) -> do
put xs
- return $ Cite cs (walk fixLinks $ B.toList x)
+ return $ Cite cs (B.toList x)
insertResolvedCitations x = return x
getCitations :: Locale
@@ -419,15 +420,6 @@ mvPunct moveNotes locale (Cite cs ils : Str "." : ys)
mvPunct moveNotes locale (x:xs) = x : mvPunct moveNotes locale xs
mvPunct _ _ [] = []
--- move https://doi.org etc. prefix inside link text (#6723):
-fixLinks :: [Inline] -> [Inline]
-fixLinks (Str t : Link attr [Str u1] (u2,tit) : xs)
- | u2 == t <> u1
- = Link attr [Str (t <> u1)] (u2,tit) : fixLinks xs
-fixLinks (x:xs) = x : fixLinks xs
-fixLinks [] = []
-
-
endWithPunct :: Bool -> [Inline] -> Bool
endWithPunct _ [] = False
endWithPunct onlyFinal xs@(_:_) =
@@ -523,29 +515,6 @@ legacyDateRanges ref =
_ -> DateVal d
go x = x
-linkifyVariables :: Reference Inlines -> Reference Inlines
-linkifyVariables ref =
- ref{ referenceVariables = M.mapWithKey go $ referenceVariables ref }
- where
- go "URL" x = tolink "https://" x
- go "DOI" x = tolink "https://doi.org/" (fixShortDOI x)
- go "ISBN" x = tolink "https://worldcat.org/isbn/" x
- go "PMID" x = tolink "https://www.ncbi.nlm.nih.gov/pubmed/" x
- go "PMCID" x = tolink "https://www.ncbi.nlm.nih.gov/pmc/articles/" x
- go _ x = x
- fixShortDOI x = let x' = extractText x
- in if "10/" `T.isPrefixOf` x'
- then TextVal $ T.drop 3 x'
- -- see https://shortdoi.org
- else TextVal x'
- tolink pref x = let x' = extractText x
- x'' = if "://" `T.isInfixOf` x'
- then x'
- else pref <> x'
- in if T.null x'
- then x
- else FancyVal (B.link x'' "" (B.str x'))
-
extractText :: Val Inlines -> Text
extractText (TextVal x) = x
extractText (FancyVal x) = toText x
diff --git a/src/Text/Pandoc/Citeproc/CslJson.hs b/src/Text/Pandoc/Citeproc/CslJson.hs
index 862af5188..43c1a87ec 100644
--- a/src/Text/Pandoc/Citeproc/CslJson.hs
+++ b/src/Text/Pandoc/Citeproc/CslJson.hs
@@ -28,6 +28,7 @@ fromCslJson (CslSub x) = B.subscript (fromCslJson x)
fromCslJson (CslSup x) = B.superscript (fromCslJson x)
fromCslJson (CslNoCase x) = B.spanWith ("",["nocase"],[]) (fromCslJson x)
fromCslJson (CslDiv t x) = B.spanWith ("",["csl-" <> t],[]) (fromCslJson x)
+fromCslJson (CslLink u x) = B.link u "" (fromCslJson x)
cslJsonToReferences :: ByteString -> Either String [Reference Inlines]
cslJsonToReferences raw =
diff --git a/src/Text/Pandoc/Writers/Powerpoint/Output.hs b/src/Text/Pandoc/Writers/Powerpoint/Output.hs
index feb1c08f5..e0eb72161 100644
--- a/src/Text/Pandoc/Writers/Powerpoint/Output.hs
+++ b/src/Text/Pandoc/Writers/Powerpoint/Output.hs
@@ -54,7 +54,7 @@ import System.FilePath.Glob
import Text.DocTemplates (FromContext(lookupContext), Context)
import Text.DocLayout (literal)
import Text.TeXMath
-import Text.Pandoc.Logging (LogMessage(TemplateWarning))
+import Text.Pandoc.Logging (LogMessage(PowerpointTemplateWarning))
import Text.Pandoc.Writers.Math (convertMath)
import Text.Pandoc.Writers.Powerpoint.Presentation
import Text.Pandoc.Shared (tshow, stringify)
@@ -457,11 +457,11 @@ presentationToArchive opts meta pres = do
<> "reference doc or in the default "
<> "reference doc included with pandoc."))
(Nothing, Just ((element, path, entry) :| _)) -> do
- P.logOutput (PowerpointTemplateWarning
- ("Couldn't find layout named \""
- <> layoutTitle <> "\" in provided "
- <> "reference doc. Falling back to "
- <> "the default included with pandoc."))
+ P.report (PowerpointTemplateWarning
+ ("Couldn't find layout named \""
+ <> layoutTitle <> "\" in provided "
+ <> "reference doc. Falling back to "
+ <> "the default included with pandoc."))
pure SlideLayout { slElement = element
, slPath = path
, slEntry = entry
diff --git a/test/command/pandoc-citeproc-31.md b/test/command/pandoc-citeproc-31.md
index a06b2ae41..91aaa8f0b 100644
--- a/test/command/pandoc-citeproc-31.md
+++ b/test/command/pandoc-citeproc-31.md
@@ -29,8 +29,9 @@ Foo.[^1] Bar.[^2] Baz.[^3]
::: {#refs .references .csl-bib-body}
::: {#ref-item1 .csl-entry}
-Olson HA, 'Codes, Costs, and Critiques: The Organization of Information
-in *Library Quarterly*, 1931--2004' (2006) 76 *Library Quarterly* 19
+Olson HA, '[Codes, Costs, and Critiques: The Organization of Information
+in *Library Quarterly*, 1931--2004](https://doi.org/10.1086/504343)'
+(2006) 76 *Library Quarterly* 19
:::
::: {#ref-item2 .csl-entry}
diff --git a/test/command/pandoc-citeproc-327.md b/test/command/pandoc-citeproc-327.md
index 92b29bdf8..5cfd59576 100644
--- a/test/command/pandoc-citeproc-327.md
+++ b/test/command/pandoc-citeproc-327.md
@@ -44,8 +44,8 @@ I referenced something here^\[1\]^
::: {#refs .references .csl-bib-body}
::: {#ref-LiLiaoDongWanHaiYuDiQiDongWuCiJiShengChanLiYanJiuJiShengJingGuaYiXingPingJie2017 .csl-entry}
[\[1\] ]{.csl-left-margin}[李轶平, 于旭光, 孙明, 等.
-辽东湾海域底栖动物次级生产力研究及生境适宜性评价\[J\]. 水产科学,
-2017(06): 728--734.]{.csl-right-inline}
+[辽东湾海域底栖动物次级生产力研究及生境适宜性评价](http://kns.cnki.net/kns/detail/detail.aspx?QueryID=4&CurRec=4&recid=&FileName=CHAN201706006&DbName=CJFDLAST2018&DbCode=CJFQ&yx=Y&pr=&URLID=21.1110.S.20171129.1725.006)\[J\].
+水产科学, 2017(06): 728--734.]{.csl-right-inline}
:::
:::
```
diff --git a/test/command/pandoc-citeproc-338.md b/test/command/pandoc-citeproc-338.md
index 3250b680e..c9cf0d254 100644
--- a/test/command/pandoc-citeproc-338.md
+++ b/test/command/pandoc-citeproc-338.md
@@ -28,8 +28,7 @@ references:
::: {#ref-item-1 .csl-entry}
[Wolfinger, Christine]{.smallcaps}: *Keine Angst vor Linux, Unix: ein
Lehrbuch für Linux- und Unix-Anwender*. 11., vollst. überarb. Aufl.
-Aufl. Berlin \[u.a.\] : Springer Vieweg, 2013
---- ISBN [978-3-642-32078-1](https://worldcat.org/isbn/978-3-642-32078-1)
+Aufl. Berlin \[u.a.\] : Springer Vieweg, 2013 --- ISBN 978-3-642-32078-1
:::
:::
```
diff --git a/test/command/pandoc-citeproc-386.md b/test/command/pandoc-citeproc-386.md
index 6f346e7db..ae709fc34 100644
--- a/test/command/pandoc-citeproc-386.md
+++ b/test/command/pandoc-citeproc-386.md
@@ -28,8 +28,8 @@ references:
::: {#refs .references .csl-bib-body line-spacing="2"}
::: {#ref-ding_metallic_2012 .csl-entry}
-[\[1\] ]{.csl-left-margin}[K. Ding, C. Z. Ning, *Light Sci. Appl.*
-**2012**, *1*, e20.]{.csl-right-inline}
+[[\[1\]K. Ding, C. Z. Ning, *Light Sci. Appl.* **2012**, *1*,
+e20](https://doi.org/10.1038/lsa.2012.20)]{.csl-left-margin}.
:::
:::
```