From 83caeb9854d115f6b7d34ef4f8998230c602ee80 Mon Sep 17 00:00:00 2001 From: Zeping Lee Date: Thu, 17 Nov 2022 11:13:55 +0800 Subject: [PATCH] Fix missing DOI prefix (fix #28) --- CHANGELOG.md | 1 + citeproc/citeproc-engine.lua | 9 +- citeproc/citeproc-node-text.lua | 21 +- test/citeproc-test.log | 2 +- test/local/bugreports_issue_28.txt | 2058 ++++++++++++++++++++++++++++ test/local/wrappers_DOI.txt | 3 +- test/local/wrappers_URL.txt | 3 +- 7 files changed, 2076 insertions(+), 21 deletions(-) create mode 100644 test/local/bugreports_issue_28.txt diff --git a/CHANGELOG.md b/CHANGELOG.md index 818e46db..5e3481f6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -21,6 +21,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Fix an error in checking the plurity of `number-of-pages` ([#27](https://github.com/zepinglee/citeproc-lua/issues/27)). - Fix an error in converting value `"2nd"` to its ordinal form ([#27](https://github.com/zepinglee/citeproc-lua/issues/27)). +- Fix missing DOI prefix when used with `hyperref` ([#28](https://github.com/zepinglee/citeproc-lua/issues/28)). ## [v0.2.2] - 2022-09-23 diff --git a/citeproc/citeproc-engine.lua b/citeproc/citeproc-engine.lua index a15694e0..db56c046 100644 --- a/citeproc/citeproc-engine.lua +++ b/citeproc/citeproc-engine.lua @@ -50,8 +50,7 @@ function CiteProc.new(sys, style, lang, force_lang) o.opt = { -- Similar to citeproc-js's development_extensions.wrap_url_and_doi - url_link = false, - doi_link = false, -- also applied to PMID and PMCID + wrap_url_and_doi = false, title_link = false, } @@ -600,13 +599,11 @@ function CiteProc:set_output_format(format) end function CiteProc:enable_linking() - self.opt.url_link = true - self.opt.doi_link = true + self.opt.wrap_url_and_doi = true end function CiteProc:disable_linking() - self.opt.url_link = false - self.opt.doi_link = false + self.opt.wrap_url_and_doi = false end function CiteProc.create_element_tree(node) diff --git a/citeproc/citeproc-node-text.lua b/citeproc/citeproc-node-text.lua index 396d6e95..242cb266 100644 --- a/citeproc/citeproc-node-text.lua +++ b/citeproc/citeproc-node-text.lua @@ -93,10 +93,8 @@ function Text:build_variable_ir(engine, state, context) -- if not engine.opt then -- print(debug.traceback()) -- end - if (variable == "URL" and engine.opt.url_link) or - (variable == "DOI" and engine.opt.doi_link) or - (variable == "PMID" and engine.opt.doi_link) or - (variable == "PMID" and engine.opt.doi_link) then + if engine.opt.wrap_url_and_doi and (variable == "URL" or variable == "DOI" or + variable == "PMID" or variable == "PMID") then inlines = self:render_linked(engine, state, context, variable, text) else inlines = self:render_text_inlines(text, context) @@ -119,14 +117,13 @@ end function Text:render_linked(engine, state, context, variable, text) local href + local url_prefix = false -- The prefix is used as part of the URL. if variable == "URL" then href = text - elseif self.affixes and self.affixes.prefix then - if string.match(self.affixes.prefix, "https?://") then - text = self.affixes.prefix .. text - self.affixes.prefix = nil - href = text - end + elseif self.affixes and self.affixes.prefix and string.match(self.affixes.prefix, "https?://") then + text = self.affixes.prefix .. text + href = text + url_prefix = true elseif variable == "DOI" then href = "https://doi.org/" .. text elseif variable == "PMID" then @@ -134,6 +131,7 @@ function Text:render_linked(engine, state, context, variable, text) elseif variable == "PMCID" then href = "https://www.ncbi.nlm.nih.gov/pmc/articles/" .. text end + local inlines = {Linked:new(text, href)} local output_format = context.format local localized_quotes = nil @@ -142,6 +140,9 @@ function Text:render_linked(engine, state, context, variable, text) end inlines = output_format:with_format(inlines, self.formatting) inlines = output_format:affixed_quoted(inlines, self.affixes, localized_quotes) + if url_prefix then + table.remove(inlines, 1) + end return output_format:with_display(inlines, self.display) end diff --git a/test/citeproc-test.log b/test/citeproc-test.log index 77c67e06..21d317f8 100644 --- a/test/citeproc-test.log +++ b/test/citeproc-test.log @@ -38,4 +38,4 @@ unicode 1 0 0 0 variables 5 0 0 0 virtual 1 0 0 0 -------------- ------- ------- ------- ------- -(all) 849 0 0 0 +(all) 850 0 0 0 diff --git a/test/local/bugreports_issue_28.txt b/test/local/bugreports_issue_28.txt new file mode 100644 index 00000000..f3036e89 --- /dev/null +++ b/test/local/bugreports_issue_28.txt @@ -0,0 +1,2058 @@ +>>===== MODE =====>> +bibliography +<<===== MODE =====<< + + +>>===== OPTIONS =====>> +{ + "wrap_url_and_doi": true +} +<<===== OPTIONS =====<< + + +>>===== RESULT =====>> +
+
Edge-Garza, D. A., Rowland, T. V., Haendiges, S., & Peace, C. (2014). A high-throughput and cost-efficient DNA extraction protocol for the tree fruit crops of apple, sweet cherry, and peach relying on silica beads during tissue sampling. Molecular Breeding, 34(4), 2225–2228. https://doi.org/10.1007/s11032-014-0160-x
+
Paris, J. R., Stevens, J. R., & Catchen, J. M. (2017). Lost in parameter space: A road map for Stacks. Methods in Ecology and Evolution, 8, 1360–1373. https://doi.org/10.1111/2041-210X.12775
+
Peterson, B. K., Weber, J. N., Kay, E. H., Fisher, H. S., & Hoekstra, H. E. (2012). Double digest RADseq: an inexpensive method for de novo SNP discovery and genotyping in model and non-model species. PLoS ONE, 7(5), e37135. https://doi.org/10.1371/journal.pone.0037135
+
+<<===== RESULT =====<< + + + +>>===== CSL =====>> + + + +<<===== CSL =====<< + +>>===== INPUT =====>> +[ + { + "DOI" : "10.1007/s11032-014-0160-x", + "ISSN" : "1380-3743, 1572-9788", + "author" : [ + { + "family" : "Edge-Garza", + "given" : "Daniel A." + }, + { + "family" : "Rowland", + "given" : "Terrence V." + }, + { + "family" : "Haendiges", + "given" : "Stacey" + }, + { + "family" : "Peace", + "given" : "Cameron" + } + ], + "container-title" : "Molecular Breeding", + "id" : "edge-garza.etal-2014-Mol.Breed.", + "issue" : "4", + "issued" : { + "date-parts" : [ + [ 2014, 12, 1 ] + ] + }, + "page" : "2225-2228", + "title" : "A high-throughput and cost-efficient DNA extraction protocol for the tree fruit crops of apple, sweet cherry, and peach relying on silica beads during tissue sampling", + "type" : "article-journal", + "volume" : "34" + }, + { + "DOI" : "10.1111/2041-210X.12775", + "ISSN" : "2041-210X", + "author" : [ + { + "family" : "Paris", + "given" : "Josephine R" + }, + { + "family" : "Stevens", + "given" : "Jamie R" + }, + { + "family" : "Catchen", + "given" : "Julian M" + } + ], + "container-title" : "Methods in Ecology and Evolution", + "container-title-short" : "Methods Ecol Evol", + "id" : "paris.etal-2017-MethodsEcolEvola", + "issued" : { + "date-parts" : [ + [ 2017, 3, 1 ] + ] + }, + "page" : "1360-1373", + "title" : "Lost in parameter space: A road map for Stacks", + "title-short" : "Lost in parameter space", + "type" : "article-journal", + "volume" : "8" + }, + { + "DOI" : "10.1371/journal.pone.0037135", + "ISSN" : "1932-6203", + "author" : [ + { + "family" : "Peterson", + "given" : "Brant K." + }, + { + "family" : "Weber", + "given" : "Jesse N." + }, + { + "family" : "Kay", + "given" : "Emily H." + }, + { + "family" : "Fisher", + "given" : "Heidi S." + }, + { + "family" : "Hoekstra", + "given" : "Hopi E." + } + ], + "container-title" : "PLoS ONE", + "id" : "peterson.etal-2012-PLoSONE", + "issue" : "5", + "issued" : { + "date-parts" : [ + [ 2012, 5, 31 ] + ] + }, + "page" : "e37135", + "title" : "Double digest RADseq: an inexpensive method for de novo SNP discovery and genotyping in model and non-model species", + "title-short" : "Double Digest RADseq", + "type" : "article-journal", + "volume" : "7" + } +] + +<<===== INPUT =====<< + + + +>>===== VERSION =====>> +1.0 +<<===== VERSION =====<< diff --git a/test/local/wrappers_DOI.txt b/test/local/wrappers_DOI.txt index 07c345d0..1ca810c5 100644 --- a/test/local/wrappers_DOI.txt +++ b/test/local/wrappers_DOI.txt @@ -5,8 +5,7 @@ citation >>===== OPTIONS =====>> { - "url_link": true, - "doi_link": true + "wrap_url_and_doi": true } <<===== OPTIONS =====<< diff --git a/test/local/wrappers_URL.txt b/test/local/wrappers_URL.txt index e40d4c0d..fcc6caf5 100644 --- a/test/local/wrappers_URL.txt +++ b/test/local/wrappers_URL.txt @@ -5,8 +5,7 @@ citation >>===== OPTIONS =====>> { - "url_link": true, - "doi_link": true + "wrap_url_and_doi": true } <<===== OPTIONS =====<<