diff options
Diffstat (limited to 'Master/texmf-dist/scripts/citation-style-language/citeproc-cli.lua')
-rw-r--r-- | Master/texmf-dist/scripts/citation-style-language/citeproc-cli.lua | 35 |
1 files changed, 22 insertions, 13 deletions
diff --git a/Master/texmf-dist/scripts/citation-style-language/citeproc-cli.lua b/Master/texmf-dist/scripts/citation-style-language/citeproc-cli.lua index 4938267d3a1..709e676ec38 100644 --- a/Master/texmf-dist/scripts/citation-style-language/citeproc-cli.lua +++ b/Master/texmf-dist/scripts/citation-style-language/citeproc-cli.lua @@ -1,6 +1,6 @@ -- --- Copyright (c) 2021-2022 Zeping Lee +-- Copyright (c) 2021-2023 Zeping Lee -- Released under the MIT license. -- Repository: https://github.com/zepinglee/citeproc-lua -- @@ -10,9 +10,10 @@ local cli = {} require("lualibs") local citeproc = require("citeproc") -local bibtex -- = require("citeproc-bibtex") -- load on demand +local bibtex2csl -- = require("citeproc-bibtex-parser") -- load on demand local util = require("citeproc-util") local core = require("citeproc-latex-core") +local latex_parser = require("citeproc-latex-parser") local function getopt( arg, options ) @@ -68,8 +69,8 @@ end local function convert_bib(path, output_path) local contents = util.read_file(path) - bibtex = bibtex or require("citeproc-bibtex") - local data = bibtex.parse(contents) + bibtex2csl = bibtex2csl or require("citeproc-bibtex2csl") + local csl_data = bibtex2csl.parse_bibtex_to_csl(contents, true, true, true, true) if not output_path then output_path = string.gsub(path, "%.bib$", ".json") end @@ -78,7 +79,7 @@ local function convert_bib(path, output_path) util.error(string.format('Cannot write "%s".', output_path)) return end - file:write(utilities.json.tojson(data) .. "\n") + file:write(utilities.json.tojson(csl_data) .. "\n") file:close() end @@ -97,24 +98,26 @@ local function read_aux_file(aux_file) end for line in file:lines() do local match - match = string.match(line, "^\\bibstyle%s*(%b{})") + -- TODO: Use lpeg-based method and detect multiple lines + match = string.match(line, "^\\csl@aux@style%s*(%b{})") if match then bib_style = string.sub(match, 2, -2) else - match = string.match(line, "^\\csl@data%s*(%b{})") + match = string.match(line, "^\\csl@aux@data%s*(%b{})") if match then for _, bib in ipairs(util.split(string.sub(match, 2, -2), "%s*,%s*")) do table.insert(bib_files, bib) end else - match = string.match(line, "^\\citation%s*(%b{})") + match = string.match(line, "^\\csl@aux@cite%s*(%b{})") if match then local citation = core.make_citation(string.sub(match, 2, -2)) table.insert(citations, citation) else - match = string.match(line, "^\\csloptions%s*(%b{})") + match = string.match(line, "^\\csl@aux@options%s*(%b{})") if match then - for key, value in string.gmatch(match, "([%w-]+)=(%w+)") do + local options = latex_parser.parse_prop(string.sub(match, 2, -2)) + for key, value in pairs(options) do csl_options[key] = value end end @@ -138,7 +141,7 @@ local function process_aux_file(aux_file) local lang = csl_options.locale local engine = core.init(style_name, bib_files, lang) - if csl_options.linking == "true" then + if csl_options.linking then engine:enable_linking() end local style_class = engine:get_style_class() @@ -159,13 +162,19 @@ local function process_aux_file(aux_file) local citation_id = citation.citationID if citation_id ~= "@nocite" then local citation_str = citation_strings[citation_id] - output_string = output_string .. string.format("\\cslcite{%s}{%s}\n", citation_id, citation_str) + output_string = output_string .. string.format("\\cslcitation{%s}{%s}\n", citation_id, citation_str) end end output_string = output_string .. "\n" + local categories_str = csl_options["categories"] + if categories_str then + core.set_categories(engine, categories_str) + end + + local filter_str = csl_options["bib-filter"] - local result = core.make_bibliography(engine) + local result = core.make_bibliography(engine, filter_str) output_string = output_string .. result local output_path = string.gsub(aux_file, "%.aux$", ".bbl") |