Skip to content

Commit

Permalink
Include 10/ prefix in short DOI links.
Browse files Browse the repository at this point in the history
Closes #136.
  • Loading branch information
jgm committed Jun 3, 2024
1 parent 76f7f13 commit c7d81a3
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 12 deletions.
2 changes: 1 addition & 1 deletion src/Citeproc/Eval.hs
Original file line number Diff line number Diff line change
Expand Up @@ -1616,7 +1616,7 @@ eText (TextVariable varForm v) = do
coerce (referenceId ref)
return NullOutput

"DOI" -> handleIdent fixShortDOI IdentDOI
"DOI" -> handleIdent id IdentDOI
"PMCID" -> handleIdent id IdentPMCID
"PMID" -> handleIdent id IdentPMID
"URL" -> handleIdent id IdentURL
Expand Down
4 changes: 3 additions & 1 deletion src/Citeproc/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -1483,7 +1483,7 @@ data Identifier =
identifierToURL :: Identifier -> Text
identifierToURL ident =
case ident of
IdentDOI t -> tolink "https://doi.org/" (fixShortDOI t)
IdentDOI t -> tolink "https://doi.org/" t
IdentPMCID t -> tolink "https://www.ncbi.nlm.nih.gov/pmc/articles/" t
IdentPMID t -> tolink "https://www.ncbi.nlm.nih.gov/pubmed/" t
IdentURL t -> tolink "https://" t
Expand All @@ -1492,6 +1492,8 @@ identifierToURL ident =
then x
else pref <> x

{-# DEPRECATED fixShortDOI
"This function is no longer used and will be removed." #-}
-- see https://shortdoi.org
fixShortDOI :: Text -> Text
fixShortDOI x = if "10/" `T.isPrefixOf` x
Expand Down
6 changes: 3 additions & 3 deletions test/extra/link_bibitems.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ bibliography
>>===== RESULT =====>>
<div class="csl-bib-body">
<div class="csl-entry"><a href="https://doi.org/10.1021/ja01577a030">Apple. 2010</a></div>
<div class="csl-entry"><a href="https://doi.org/bbbbb">Blueberry. 2011</a></div>
<div class="csl-entry"><a href="https://doi.org/10/bbbbb">Blueberry. 2011</a></div>
<div class="csl-entry"><a href="https://pandoc.org/">Cherry. 2012</a></div>
<div class="csl-entry"><a href="https://www.ncbi.nlm.nih.gov/pubmed/30310042">Durian. 2013</a></div>
<div class="csl-entry"><a href="https://www.ncbi.nlm.nih.gov/pmc/articles/PMC3531190">Elderberry. 2014</a></div>
<div class="csl-entry"><a href="https://doi.org/bbbbb">Fig. 2015</a></div>
<div class="csl-entry"><a href="https://doi.org/10/bbbbb">Fig. 2015</a></div>
<div class="csl-entry"><a href="https://www.ncbi.nlm.nih.gov/pmc/articles/PMC3531190">Grapefruit. 2016</a></div>
<div class="csl-entry"><a href="https://www.ncbi.nlm.nih.gov/pubmed/30310042">Honeydew. 2017</a></div>
</div>
Expand Down Expand Up @@ -176,4 +176,4 @@ bibliography

>>===== VERSION =====>>
1.0
<<===== VERSION =====<<
<<===== VERSION =====<<
6 changes: 2 additions & 4 deletions test/extra/link_plainurls.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ This test checks the following properties:
- plain URLs appearing in bibliography items should be linkified
- when a link's prefix+anchor matches its target, the
prefix should be included in the anchor
- shortDOIs should be handled correctly, meaning that every shortDOI of
the form 10/abcde should be converted to the DOI abcde

>>===== MODE =====>>
bibliography
Expand All @@ -18,7 +16,7 @@ bibliography
>>===== RESULT =====>>
<div class="csl-bib-body">
<div class="csl-entry">Apple. AAAA. 2010. <a href="https://doi.org/10.1021/ja01577a030">https://doi.org/10.1021/ja01577a030</a></div>
<div class="csl-entry">Blueberry. BBBB. 2011. <a href="https://doi.org/bbbbb">https://doi.org/bbbbb</a></div>
<div class="csl-entry">Blueberry. BBBB. 2011. <a href="https://doi.org/10/bbbbb">https://doi.org/10/bbbbb</a></div>
<div class="csl-entry">Cherry. CCCC. 2012. <a href="https://pandoc.org/">https://pandoc.org/</a></div>
<div class="csl-entry">Durian. DDDD. 2013. <a href="https://www.ncbi.nlm.nih.gov/pubmed/30310042">https://www.ncbi.nlm.nih.gov/pubmed/30310042</a></div>
<div class="csl-entry">Elderberry. EEEE. 2014. <a href="https://www.ncbi.nlm.nih.gov/pmc/articles/PMC3531190">https://www.ncbi.nlm.nih.gov/pmc/articles/PMC3531190</a></div>
Expand Down Expand Up @@ -149,4 +147,4 @@ bibliography

>>===== VERSION =====>>
1.0
<<===== VERSION =====<<
<<===== VERSION =====<<
6 changes: 3 additions & 3 deletions test/extra/link_titles.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ bibliography
>>===== RESULT =====>>
<div class="csl-bib-body">
<div class="csl-entry">Apple. <a href="https://doi.org/10.1021/ja01577a030">AAAA</a>. 2010</div>
<div class="csl-entry">Blueberry. <a href="https://doi.org/bbbbb">BBBB</a>. 2011</div>
<div class="csl-entry">Blueberry. <a href="https://doi.org/10/bbbbb">BBBB</a>. 2011</div>
<div class="csl-entry">Cherry. <a href="https://pandoc.org/">CCCC</a>. 2012</div>
<div class="csl-entry">Durian. <a href="https://www.ncbi.nlm.nih.gov/pubmed/30310042">DDDD</a>. 2013</div>
<div class="csl-entry">Elderberry. <a href="https://www.ncbi.nlm.nih.gov/pmc/articles/PMC3531190">EEEE</a>. 2014</div>
<div class="csl-entry">Fig. <a href="https://doi.org/bbbbb">FFFF</a>. 2015</div>
<div class="csl-entry">Fig. <a href="https://doi.org/10/bbbbb">FFFF</a>. 2015</div>
<div class="csl-entry">Grapefruit. <a href="https://www.ncbi.nlm.nih.gov/pmc/articles/PMC3531190">GGGG</a>. 2016</div>
<div class="csl-entry">Honeydew. <a href="https://www.ncbi.nlm.nih.gov/pubmed/30310042">HHHH</a>. 2017</div>
</div>
Expand Down Expand Up @@ -176,4 +176,4 @@ bibliography

>>===== VERSION =====>>
1.0
<<===== VERSION =====<<
<<===== VERSION =====<<

0 comments on commit c7d81a3

Please sign in to comment.