summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/scripts/citation-style-language
diff options
context:
space:
mode:
Diffstat (limited to 'Master/texmf-dist/scripts/citation-style-language')
-rwxr-xr-xMaster/texmf-dist/scripts/citation-style-language/citeproc6
-rw-r--r--Master/texmf-dist/scripts/citation-style-language/citeproc-bib.lua182
-rw-r--r--Master/texmf-dist/scripts/citation-style-language/citeproc-element.lua6
-rw-r--r--Master/texmf-dist/scripts/citation-style-language/citeproc-engine.lua8
-rw-r--r--Master/texmf-dist/scripts/citation-style-language/citeproc-formats.lua8
-rw-r--r--Master/texmf-dist/scripts/citation-style-language/citeproc-node-choose.lua8
-rw-r--r--Master/texmf-dist/scripts/citation-style-language/citeproc-node-date.lua6
-rw-r--r--Master/texmf-dist/scripts/citation-style-language/citeproc-node-group.lua6
-rw-r--r--Master/texmf-dist/scripts/citation-style-language/citeproc-node-label.lua6
-rw-r--r--Master/texmf-dist/scripts/citation-style-language/citeproc-node-layout.lua6
-rw-r--r--Master/texmf-dist/scripts/citation-style-language/citeproc-node-locale.lua6
-rw-r--r--Master/texmf-dist/scripts/citation-style-language/citeproc-node-names.lua6
-rw-r--r--Master/texmf-dist/scripts/citation-style-language/citeproc-node-number.lua6
-rw-r--r--Master/texmf-dist/scripts/citation-style-language/citeproc-node-sort.lua6
-rw-r--r--Master/texmf-dist/scripts/citation-style-language/citeproc-node-style.lua6
-rw-r--r--Master/texmf-dist/scripts/citation-style-language/citeproc-node-text.lua10
-rw-r--r--Master/texmf-dist/scripts/citation-style-language/citeproc-nodes.lua9
-rw-r--r--Master/texmf-dist/scripts/citation-style-language/citeproc-richtext.lua8
-rw-r--r--Master/texmf-dist/scripts/citation-style-language/citeproc-util.lua8
-rwxr-xr-xMaster/texmf-dist/scripts/citation-style-language/citeproc.lua11
-rw-r--r--Master/texmf-dist/scripts/citation-style-language/csl-core.lua80
-rw-r--r--Master/texmf-dist/scripts/citation-style-language/csl.lua8
22 files changed, 338 insertions, 68 deletions
diff --git a/Master/texmf-dist/scripts/citation-style-language/citeproc b/Master/texmf-dist/scripts/citation-style-language/citeproc
index 3a72892ec7c..27663952bd7 100755
--- a/Master/texmf-dist/scripts/citation-style-language/citeproc
+++ b/Master/texmf-dist/scripts/citation-style-language/citeproc
@@ -1,5 +1,11 @@
#!/usr/bin/env texlua
+--
+-- Copyright (c) 2021-2022 Zeping Lee
+-- Released under the MIT license.
+-- Repository: https://github.com/zepinglee/citeproc-lua
+--
+
kpse.set_program_name("luatex")
require("lualibs")
diff --git a/Master/texmf-dist/scripts/citation-style-language/citeproc-bib.lua b/Master/texmf-dist/scripts/citation-style-language/citeproc-bib.lua
index d3532c098be..b99ba955dda 100644
--- a/Master/texmf-dist/scripts/citation-style-language/citeproc-bib.lua
+++ b/Master/texmf-dist/scripts/citation-style-language/citeproc-bib.lua
@@ -1,3 +1,9 @@
+--
+-- Copyright (c) 2021-2022 Zeping Lee
+-- Released under the MIT license.
+-- Repository: https://github.com/zepinglee/citeproc-lua
+--
+
--[[
A naive implementation of a Bib(La)TeX dateabase (.bib) parser
References:
@@ -45,16 +51,12 @@ function bib.parse_item(contents)
return nil
end
- local item = {id = id}
+ local item = {id = id, ["citation-key"] = id}
bib_type = string.lower(bib_type)
local type_data = bib.bib_data.types[bib_type]
- if type_data then
- if type_data.csl then
- item.type = type_data.csl
- else
- item.type = "document"
- end
+ if type_data and type_data.csl then
+ item.type = type_data.csl
else
item.type = "document"
end
@@ -341,7 +343,9 @@ function bib.parse_single_date(str)
return date
end
+
function bib.process_special_fields(item, bib_fields)
+ -- Default entry type `document`
if item.type == "document" then
if item.URL then
item.type = "webpage"
@@ -350,12 +354,12 @@ function bib.process_special_fields(item, bib_fields)
end
end
- if item.type == "article-journal" then
- if not item["container-title"] then
- item.type = "article"
- end
+ -- event-title: for compatibility with CSL v1.0.1 and earlier versions
+ if item["event-title"] then
+ item.event = item["event-title"]
end
+ -- issued date
if bib_fields.year and not item.issued then
item.issued = bib.parse_date(bib_fields.year)
end
@@ -368,28 +372,158 @@ function bib.process_special_fields(item, bib_fields)
end
end
+ -- language: convert `babel` language to ISO 639-1 language code
+ if not item.language and bib_fields.language then
+ item.language = bib_fields.language
+ end
+ if item.language then
+ local language_code = bib.babel_locale_mapping[item.language]
+ if language_code then
+ item.language = language_code
+ end
+ end
+ -- if not item.language then
+ -- if util.has_cjk_char(item.title) then
+ -- item.language = "zh"
+ -- end
+ -- end
+
+ -- number
if item.number then
- if not item.issue and item.type == "article-journal" or item.type == "article-magazine" or item.type == "article-newspaper" or item.type == "periodical" then
- item.issue = item.number
- item.number = nil
- elseif item.type == "patent" or item.type == "report" or item.type == "standard" then
- else
+ if item.type == "article-journal" or item.type == "article-magazine" or item.type == "article-newspaper" or item.type == "periodical" then
+ if not item.issue then
+ item.issue = item.number
+ item.number = nil
+ end
+ elseif item["collection-title"] and not item["collection-number"] then
item["collection-number"] = item.number
item.number = nil
end
end
- if not item.PMID and bib_fields.eprint and string.lower(bib_fields.eprinttype) == "pubmed" then
+ -- PMID
+ if bib_fields.eprint and string.lower(bib_fields.eprinttype) == "pubmed" and not item.PMID then
item.PMID = bib_fields.eprint
end
- -- if not item.language then
- -- if util.has_cjk_char(item.title) then
- -- item.language = "zh"
- -- else
- -- item.language = "en"
- -- end
- -- end
end
+
+bib.babel_locale_mapping = {
+ acadian = "fr-CA",
+ american = "en-US",
+ australian = "en-AU",
+ afrikaans = "af-ZA",
+ albanian = "sq-AL",
+ amharic = "am-ET",
+ arabic = "ar",
+ armenian = "hy-AM",
+ asturian = "ast-ES",
+ austrian = "de-AT",
+ bahasa = "id-ID",
+ bahasai = "id-ID",
+ bahasam = "id-ID",
+ basque = "eu-ES",
+ bengali = "bn-BD",
+ bgreek = "el-GR",
+ brazil = "pt-BR",
+ brazilian = "pt-BR",
+ breton = "br-FR",
+ british = "en-GB",
+ bulgarian = "bg-BG",
+ canadian = "en-CA",
+ canadien = "fr-CA",
+ catalan = "ca-AD",
+ coptic = "cop",
+ croatian = "hr-HR",
+ czech = "cs-CZ",
+ danish = "da-DK",
+ divehi = "dv-MV",
+ dutch = "nl-NL",
+ english = "en-US",
+ esperanto = "eo-001",
+ estonian = "et-EE",
+ ethiopia = "am-ET",
+ farsi = "fa-IR",
+ finnish = "fi-FI",
+ francais = "fr-FR",
+ french = "fr-FR",
+ frenchle = "fr-FR",
+ friulan = "fur-IT",
+ galician = "gl-ES",
+ german = "de-DE",
+ germanb = "de-DE",
+ greek = "el-GR",
+ hebrew = "he-IL",
+ hindi = "hi-IN",
+ ibygreek = "el-CY",
+ icelandic = "is-IS",
+ indon = "id-ID",
+ indonesia = "id-ID",
+ interlingua = "ia-FR",
+ irish = "ga-IE",
+ italian = "it-IT",
+ japanese = "ja-JP",
+ kannada = "kn-IN",
+ lao = "lo-LA",
+ latin = "la-Latn",
+ latvian = "lv-LV",
+ lithuanian = "lt-LT",
+ lowersorbian = "dsb-DE",
+ lsorbian = "dsb-DE",
+ magyar = "hu-HU",
+ malay = "id-ID",
+ malayalam = "ml-IN",
+ marathi = "mr-IN",
+ meyalu = "id-ID",
+ mongolian = "mn-Cyrl",
+ naustrian = "de-AT",
+ newzealand = "en-NZ",
+ ngerman = "de-DE",
+ nko = "ha-NG",
+ norsk = "nb-NO",
+ norwegian = "nn-NO",
+ nynorsk = "nn-NO",
+ occitan = "oc-FR",
+ piedmontese = "pms-IT",
+ pinyin = "pny",
+ polish = "pl-PL",
+ polutonikogreek = "el-GR",
+ portuges = "pt-PT",
+ portuguese = "pt-PT",
+ romanian = "ro-RO",
+ romansh = "rm-CH",
+ russian = "ru-RU",
+ samin = "se-NO",
+ sanskrit = "sa-IN",
+ scottish = "gd-GB",
+ serbian = "sr-Latn",
+ serbianc = "sr-Cyrl",
+ slovak = "sk-SK",
+ slovene = "sl-SI",
+ slovenian = "sl-SI",
+ spanish = "es-ES",
+ swedish = "sv-SE",
+ swiss = "de-CH",
+ swissgerman = "de-CH",
+ nswissgerman = "de-CH",
+ syriac = "syc",
+ tamil = "ta-IN",
+ telugu = "te-IN",
+ thai = "th-TH",
+ thaicjk = "th-TH",
+ tibetan = "bo-CN",
+ turkish = "tr-TR",
+ turkmen = "tk-TM",
+ ukrainian = "uk-UA",
+ urdu = "ur-IN",
+ UKenglish = "en-UK",
+ uppersorbian = "hsb-DE",
+ USenglish = "en-US",
+ usorbian = "hsb-DE",
+ vietnamese = "vi-VN",
+ welsh = "cy-GB",
+}
+
+
return bib
diff --git a/Master/texmf-dist/scripts/citation-style-language/citeproc-element.lua b/Master/texmf-dist/scripts/citation-style-language/citeproc-element.lua
index 58d3402d2c5..0e7abf87e35 100644
--- a/Master/texmf-dist/scripts/citation-style-language/citeproc-element.lua
+++ b/Master/texmf-dist/scripts/citation-style-language/citeproc-element.lua
@@ -1,3 +1,9 @@
+--
+-- Copyright (c) 2021-2022 Zeping Lee
+-- Released under the MIT license.
+-- Repository: https://github.com/zepinglee/citeproc-lua
+--
+
local element = {}
local unicode = require("unicode")
diff --git a/Master/texmf-dist/scripts/citation-style-language/citeproc-engine.lua b/Master/texmf-dist/scripts/citation-style-language/citeproc-engine.lua
index ac8cc9c44e3..33a5a08e080 100644
--- a/Master/texmf-dist/scripts/citation-style-language/citeproc-engine.lua
+++ b/Master/texmf-dist/scripts/citation-style-language/citeproc-engine.lua
@@ -1,6 +1,8 @@
---[[
- Copyright (C) 2021 Zeping Lee
---]]
+--
+-- Copyright (c) 2021-2022 Zeping Lee
+-- Released under the MIT license.
+-- Repository: https://github.com/zepinglee/citeproc-lua
+--
local engine = {}
diff --git a/Master/texmf-dist/scripts/citation-style-language/citeproc-formats.lua b/Master/texmf-dist/scripts/citation-style-language/citeproc-formats.lua
index 854a528b95d..fd9621936c4 100644
--- a/Master/texmf-dist/scripts/citation-style-language/citeproc-formats.lua
+++ b/Master/texmf-dist/scripts/citation-style-language/citeproc-formats.lua
@@ -1,6 +1,8 @@
---[[
- Copyright (C) 2021 Zeping Lee
---]]
+--
+-- Copyright (c) 2021-2022 Zeping Lee
+-- Released under the MIT license.
+-- Repository: https://github.com/zepinglee/citeproc-lua
+--
local util = require("citeproc-util")
diff --git a/Master/texmf-dist/scripts/citation-style-language/citeproc-node-choose.lua b/Master/texmf-dist/scripts/citation-style-language/citeproc-node-choose.lua
index aa36e2c8c37..e48731406c5 100644
--- a/Master/texmf-dist/scripts/citation-style-language/citeproc-node-choose.lua
+++ b/Master/texmf-dist/scripts/citation-style-language/citeproc-node-choose.lua
@@ -1,3 +1,9 @@
+--
+-- Copyright (c) 2021-2022 Zeping Lee
+-- Released under the MIT license.
+-- Repository: https://github.com/zepinglee/citeproc-lua
+--
+
local choose = {}
local element = require("citeproc-element")
@@ -50,7 +56,7 @@ If.render = function (self, item, context)
local locator_label = item.label or "page"
local res = locator_label == locator_type
if locator_type == "sub-verbo" then
- res = locator_label == "sub verbo"
+ res = locator_label == "sub-verbo" or locator_label == "sub verbo"
end
table.insert(results, res)
end
diff --git a/Master/texmf-dist/scripts/citation-style-language/citeproc-node-date.lua b/Master/texmf-dist/scripts/citation-style-language/citeproc-node-date.lua
index 9c712a8135b..e10c1a9ac25 100644
--- a/Master/texmf-dist/scripts/citation-style-language/citeproc-node-date.lua
+++ b/Master/texmf-dist/scripts/citation-style-language/citeproc-node-date.lua
@@ -1,3 +1,9 @@
+--
+-- Copyright (c) 2021-2022 Zeping Lee
+-- Released under the MIT license.
+-- Repository: https://github.com/zepinglee/citeproc-lua
+--
+
local date_module = {}
local element = require("citeproc-element")
diff --git a/Master/texmf-dist/scripts/citation-style-language/citeproc-node-group.lua b/Master/texmf-dist/scripts/citation-style-language/citeproc-node-group.lua
index 3148e961486..51969212ba7 100644
--- a/Master/texmf-dist/scripts/citation-style-language/citeproc-node-group.lua
+++ b/Master/texmf-dist/scripts/citation-style-language/citeproc-node-group.lua
@@ -1,3 +1,9 @@
+--
+-- Copyright (c) 2021-2022 Zeping Lee
+-- Released under the MIT license.
+-- Repository: https://github.com/zepinglee/citeproc-lua
+--
+
local group = {}
local element = require("citeproc-element")
diff --git a/Master/texmf-dist/scripts/citation-style-language/citeproc-node-label.lua b/Master/texmf-dist/scripts/citation-style-language/citeproc-node-label.lua
index d8bfe2ba3d4..828f5e91222 100644
--- a/Master/texmf-dist/scripts/citation-style-language/citeproc-node-label.lua
+++ b/Master/texmf-dist/scripts/citation-style-language/citeproc-node-label.lua
@@ -1,3 +1,9 @@
+--
+-- Copyright (c) 2021-2022 Zeping Lee
+-- Released under the MIT license.
+-- Repository: https://github.com/zepinglee/citeproc-lua
+--
+
local label = {}
local element = require("citeproc-element")
diff --git a/Master/texmf-dist/scripts/citation-style-language/citeproc-node-layout.lua b/Master/texmf-dist/scripts/citation-style-language/citeproc-node-layout.lua
index 40ce358629b..944ed883a38 100644
--- a/Master/texmf-dist/scripts/citation-style-language/citeproc-node-layout.lua
+++ b/Master/texmf-dist/scripts/citation-style-language/citeproc-node-layout.lua
@@ -1,3 +1,9 @@
+--
+-- Copyright (c) 2021-2022 Zeping Lee
+-- Released under the MIT license.
+-- Repository: https://github.com/zepinglee/citeproc-lua
+--
+
local layout = {}
local richtext = require("citeproc-richtext")
diff --git a/Master/texmf-dist/scripts/citation-style-language/citeproc-node-locale.lua b/Master/texmf-dist/scripts/citation-style-language/citeproc-node-locale.lua
index e324c3502eb..92a604992c7 100644
--- a/Master/texmf-dist/scripts/citation-style-language/citeproc-node-locale.lua
+++ b/Master/texmf-dist/scripts/citation-style-language/citeproc-node-locale.lua
@@ -1,3 +1,9 @@
+--
+-- Copyright (c) 2021-2022 Zeping Lee
+-- Released under the MIT license.
+-- Repository: https://github.com/zepinglee/citeproc-lua
+--
+
local locale = {}
local element = require("citeproc-element")
diff --git a/Master/texmf-dist/scripts/citation-style-language/citeproc-node-names.lua b/Master/texmf-dist/scripts/citation-style-language/citeproc-node-names.lua
index 9958e28999e..72096a58f91 100644
--- a/Master/texmf-dist/scripts/citation-style-language/citeproc-node-names.lua
+++ b/Master/texmf-dist/scripts/citation-style-language/citeproc-node-names.lua
@@ -1,3 +1,9 @@
+--
+-- Copyright (c) 2021-2022 Zeping Lee
+-- Released under the MIT license.
+-- Repository: https://github.com/zepinglee/citeproc-lua
+--
+
local names_module = {}
local unicode = require("unicode")
diff --git a/Master/texmf-dist/scripts/citation-style-language/citeproc-node-number.lua b/Master/texmf-dist/scripts/citation-style-language/citeproc-node-number.lua
index e4fe710fd00..ba096157aa4 100644
--- a/Master/texmf-dist/scripts/citation-style-language/citeproc-node-number.lua
+++ b/Master/texmf-dist/scripts/citation-style-language/citeproc-node-number.lua
@@ -1,3 +1,9 @@
+--
+-- Copyright (c) 2021-2022 Zeping Lee
+-- Released under the MIT license.
+-- Repository: https://github.com/zepinglee/citeproc-lua
+--
+
local number_module = {}
local element = require("citeproc-element")
diff --git a/Master/texmf-dist/scripts/citation-style-language/citeproc-node-sort.lua b/Master/texmf-dist/scripts/citation-style-language/citeproc-node-sort.lua
index f36baccf00a..1b82d21b55e 100644
--- a/Master/texmf-dist/scripts/citation-style-language/citeproc-node-sort.lua
+++ b/Master/texmf-dist/scripts/citation-style-language/citeproc-node-sort.lua
@@ -1,3 +1,9 @@
+--
+-- Copyright (c) 2021-2022 Zeping Lee
+-- Released under the MIT license.
+-- Repository: https://github.com/zepinglee/citeproc-lua
+--
+
local sort = {}
local unicode = require("unicode")
diff --git a/Master/texmf-dist/scripts/citation-style-language/citeproc-node-style.lua b/Master/texmf-dist/scripts/citation-style-language/citeproc-node-style.lua
index b8386c47e7c..2fb10cc79c3 100644
--- a/Master/texmf-dist/scripts/citation-style-language/citeproc-node-style.lua
+++ b/Master/texmf-dist/scripts/citation-style-language/citeproc-node-style.lua
@@ -1,3 +1,9 @@
+--
+-- Copyright (c) 2021-2022 Zeping Lee
+-- Released under the MIT license.
+-- Repository: https://github.com/zepinglee/citeproc-lua
+--
+
local style = {}
local element = require("citeproc-element")
diff --git a/Master/texmf-dist/scripts/citation-style-language/citeproc-node-text.lua b/Master/texmf-dist/scripts/citation-style-language/citeproc-node-text.lua
index 55dd13e295c..e26a4804387 100644
--- a/Master/texmf-dist/scripts/citation-style-language/citeproc-node-text.lua
+++ b/Master/texmf-dist/scripts/citation-style-language/citeproc-node-text.lua
@@ -1,3 +1,9 @@
+--
+-- Copyright (c) 2021-2022 Zeping Lee
+-- Released under the MIT license.
+-- Repository: https://github.com/zepinglee/citeproc-lua
+--
+
local text = {}
local element = require("citeproc-element")
@@ -63,6 +69,10 @@ function Text:render (item, context)
res = richtext.new(res)
end
+ if res and variable_name == "URL" then
+ res:add_format("URL", "true")
+ end
+
res = self:strip_periods(res, context)
res = self:case(res, context)
res = self:format(res, context)
diff --git a/Master/texmf-dist/scripts/citation-style-language/citeproc-nodes.lua b/Master/texmf-dist/scripts/citation-style-language/citeproc-nodes.lua
index 255d170bc9d..69e87739b4a 100644
--- a/Master/texmf-dist/scripts/citation-style-language/citeproc-nodes.lua
+++ b/Master/texmf-dist/scripts/citation-style-language/citeproc-nodes.lua
@@ -1,7 +1,8 @@
---[[
- Copyright (C) 2021 Zeping Lee
---]]
-
+--
+-- Copyright (c) 2021-2022 Zeping Lee
+-- Released under the MIT license.
+-- Repository: https://github.com/zepinglee/citeproc-lua
+--
local style = require("citeproc-node-style")
local locale = require("citeproc-node-locale")
diff --git a/Master/texmf-dist/scripts/citation-style-language/citeproc-richtext.lua b/Master/texmf-dist/scripts/citation-style-language/citeproc-richtext.lua
index 50f78a4466d..f9afd3acc6d 100644
--- a/Master/texmf-dist/scripts/citation-style-language/citeproc-richtext.lua
+++ b/Master/texmf-dist/scripts/citation-style-language/citeproc-richtext.lua
@@ -1,6 +1,8 @@
---[[
- Copyright (C) 2021 Zeping Lee
---]]
+--
+-- Copyright (c) 2021-2022 Zeping Lee
+-- Released under the MIT license.
+-- Repository: https://github.com/zepinglee/citeproc-lua
+--
local richtext = {}
diff --git a/Master/texmf-dist/scripts/citation-style-language/citeproc-util.lua b/Master/texmf-dist/scripts/citation-style-language/citeproc-util.lua
index 9aaa0778746..c9adb6558f8 100644
--- a/Master/texmf-dist/scripts/citation-style-language/citeproc-util.lua
+++ b/Master/texmf-dist/scripts/citation-style-language/citeproc-util.lua
@@ -1,6 +1,8 @@
---[[
- Copyright (C) 2021 Zeping Lee
---]]
+--
+-- Copyright (c) 2021-2022 Zeping Lee
+-- Released under the MIT license.
+-- Repository: https://github.com/zepinglee/citeproc-lua
+--
-- load `slnunicode` from LuaTeX
local unicode = require("unicode")
diff --git a/Master/texmf-dist/scripts/citation-style-language/citeproc.lua b/Master/texmf-dist/scripts/citation-style-language/citeproc.lua
index 19f217535ed..828d9514030 100755
--- a/Master/texmf-dist/scripts/citation-style-language/citeproc.lua
+++ b/Master/texmf-dist/scripts/citation-style-language/citeproc.lua
@@ -1,7 +1,8 @@
---[[
- Copyright (C) 2021 Zeping Lee
---]]
-
+--
+-- Copyright (c) 2021-2022 Zeping Lee
+-- Released under the MIT license.
+-- Repository: https://github.com/zepinglee/citeproc-lua
+--
local citeproc = {}
@@ -9,7 +10,7 @@ local engine = require("citeproc-engine")
local bib = require("citeproc-bib")
local util = require("citeproc-util")
-citeproc.__VERSION__ = "0.1.0"
+citeproc.__VERSION__ = "0.1.1"
citeproc.new = engine.CiteProc.new
citeproc.parse_bib = bib.parse
diff --git a/Master/texmf-dist/scripts/citation-style-language/csl-core.lua b/Master/texmf-dist/scripts/citation-style-language/csl-core.lua
index 8e0448b993e..e4e2fed32e8 100644
--- a/Master/texmf-dist/scripts/citation-style-language/csl-core.lua
+++ b/Master/texmf-dist/scripts/citation-style-language/csl-core.lua
@@ -1,3 +1,9 @@
+--
+-- Copyright (c) 2021-2022 Zeping Lee
+-- Released under the MIT license.
+-- Repository: https://github.com/zepinglee/citeproc-lua
+--
+
local core = {}
local citeproc = require("citeproc")
@@ -42,12 +48,12 @@ function core.read_file(file_name, ftype, file_info)
if ftype and not util.endswith(file_name, ftype) then
file_name = file_name .. ftype
end
- core.error(string.format('Failed to find %s "%s"', file_info, file_name))
+ core.error(string.format('Cannot find %s "%s"', file_info, file_name))
return nil
end
local file = io.open(path, "r")
if not file then
- core.error(string.format('Failed to open %s "%s"', file_info, path))
+ core.error(string.format('Cannot open %s "%s"', file_info, path))
return nil
end
local contents = file:read("*a")
@@ -55,17 +61,54 @@ function core.read_file(file_name, ftype, file_info)
return contents
end
-local function load_bib(bib_files)
- local bib = {}
- for _, bib_file in ipairs(bib_files) do
- -- TODO: try to load `<bibname>.json` first?
- local bib_contents = core.read_file(bib_file, "bib", "database file")
- local file_name = bib_file
- if not util.endswith(file_name, ".bib") then
- file_name = file_name .. ".bib"
+
+local function read_data_file(data_file)
+ local file_name = data_file
+ local extension = nil
+ local contents = nil
+
+ if util.endswith(data_file, ".json") then
+ extension = ".json"
+ contents = core.read_file(data_file, nil, "database file")
+ elseif util.endswith(data_file, ".bib") then
+ extension = ".bib"
+ contents = core.read_file(data_file, "bib", "database file")
+ else
+ local path = kpse.find_file(data_file .. ".json")
+ if path then
+ file_name = data_file .. ".json"
+ extension = ".json"
+ contents = core.read_file(data_file .. ".json", nil, "database file")
+ else
+ path = kpse.find_file(data_file, "bib")
+ if path then
+ file_name = data_file .. ".bib"
+ extension = ".bib"
+ contents = core.read_file(data_file, "bib", "database file")
+ else
+ core.error(string.format('Cannot find database file "%s"', data_file .. ".json"))
+ end
end
+ end
+
+ local csl_items = nil
+
+ if extension == ".json" then
+ csl_items = utilities.json.tolua(contents)
+ elseif extension == ".bib" then
+ csl_items = citeproc.parse_bib(contents)
+ end
+
+ return file_name, csl_items
+end
+
+
+local function read_data_files(data_files)
+ local bib = {}
+ for _, data_file in ipairs(data_files) do
+ local file_name, csl_items = read_data_file(data_file)
+
-- TODO: parse bib entries on demand
- local csl_items = citeproc.parse_bib(bib_contents)
for _, item in ipairs(csl_items) do
local id = item.id
if bib[id] then
@@ -77,8 +120,10 @@ local function load_bib(bib_files)
return bib
end
-function core.make_citeproc_sys(bib_files)
- core.bib = load_bib(bib_files)
+
+
+function core.make_citeproc_sys(data_files)
+ core.bib = read_data_files(data_files)
local citeproc_sys = {
retrieveLocale = function (lang)
local locale_file_format = core.locale_file_format or "locales-%s.xml"
@@ -97,8 +142,8 @@ function core.make_citeproc_sys(bib_files)
return citeproc_sys
end
-function core.init(style_name, bib_files, lang)
- if style_name == "" or #bib_files == 0 then
+function core.init(style_name, data_files, lang)
+ if style_name == "" or #data_files == 0 then
return nil
end
local style = core.read_file(style_name .. ".csl", nil, "style file")
@@ -114,7 +159,7 @@ function core.init(style_name, bib_files, lang)
lang = nil
end
- local citeproc_sys = core.make_citeproc_sys(bib_files)
+ local citeproc_sys = core.make_citeproc_sys(data_files)
local engine = citeproc.new(citeproc_sys, style, lang, force_lang)
return engine
end
@@ -143,9 +188,6 @@ function core.make_citation(citation_info)
item_str = string.sub(item_str, 2, -2)
local cite_item = {}
for key, value in string.gmatch(item_str, "([%w%-]+)=(%b{})") do
- if key == "sub-verbo" then
- key = "sub verbo"
- end
value = string.sub(value, 2, -2)
cite_item[key] = value
end
diff --git a/Master/texmf-dist/scripts/citation-style-language/csl.lua b/Master/texmf-dist/scripts/citation-style-language/csl.lua
index 701102319be..90f5bea5880 100644
--- a/Master/texmf-dist/scripts/citation-style-language/csl.lua
+++ b/Master/texmf-dist/scripts/citation-style-language/csl.lua
@@ -1,6 +1,8 @@
---[[
- Copyright (C) 2021 Zeping Lee
---]]
+--
+-- Copyright (c) 2021-2022 Zeping Lee
+-- Released under the MIT license.
+-- Repository: https://github.com/zepinglee/citeproc-lua
+--
local csl = {}