summaryrefslogtreecommitdiff
path: root/biblio/citation-style-language/citeproc-element.lua
diff options
context:
space:
mode:
Diffstat (limited to 'biblio/citation-style-language/citeproc-element.lua')
-rw-r--r--biblio/citation-style-language/citeproc-element.lua38
1 files changed, 34 insertions, 4 deletions
diff --git a/biblio/citation-style-language/citeproc-element.lua b/biblio/citation-style-language/citeproc-element.lua
index 4ef2b7c420..4d3226dc70 100644
--- a/biblio/citation-style-language/citeproc-element.lua
+++ b/biblio/citation-style-language/citeproc-element.lua
@@ -1,5 +1,5 @@
--
--- Copyright (c) 2021-2022 Zeping Lee
+-- Copyright (c) 2021-2023 Zeping Lee
-- Released under the MIT license.
-- Repository: https://github.com/zepinglee/citeproc-lua
--
@@ -14,6 +14,7 @@ local Micro = require("citeproc-output").Micro
local util = require("citeproc-util")
+---@class Element
local Element = {
element_name = nil,
children = nil,
@@ -164,7 +165,7 @@ function Element:build_group_ir(engine, state, context)
local irs = {}
local name_count
local ir_sort_key
- local group_var = "plain"
+ local group_var = "UnresolvedPlain"
for _, child_element in ipairs(self.children) do
-- util.debug(child_element.element_name)
@@ -181,8 +182,10 @@ function Element:build_group_ir(engine, state, context)
local child_group_var = child_ir.group_var
if child_group_var == "important" then
group_var = "important"
+ elseif child_group_var == "plain" and group_var == "UnresolvedPlain" then
+ group_var = "plain"
elseif child_group_var == "missing" and child_ir._type ~= "YearSuffix" then
- if group_var == "plain" then
+ if group_var == "plain" or group_var == "UnresolvedPlain" then
group_var = "missing"
end
end
@@ -213,6 +216,8 @@ function Element:build_group_ir(engine, state, context)
ir.sort_key = ir_sort_key
ir.group_var = group_var
+ -- util.debug(ir)
+
return ir
end
@@ -488,6 +493,12 @@ end
function Element:format_page_range(number_parts, page_range_format)
local start = number_parts[1]
local stop = number_parts[2]
+
+ if string.match(start, "^%a+$") and string.match(stop, "^%a+$") then
+ -- CMoS exaple: xxv–xxviii
+ return stop
+ end
+
local start_prefix, start_num = string.match(start, "^(.-)(%d+)$")
local stop_prefix, stop_num = string.match(stop, "^(.-)(%d+)$")
if start_prefix ~= stop_prefix then
@@ -516,7 +527,15 @@ function Element:format_page_range(number_parts, page_range_format)
number_parts[2] = stop
end
+---comment
+---@param start string
+---@param stop string
+---@return string
function Element:_format_range_chicago_16(start, stop)
+ if not start then
+ print(debug.traceback())
+ end
+ stop = self:_format_range_expanded(start, stop)
if #start < 3 or string.sub(start, -2) == "00" then
return self:_format_range_expanded(start, stop)
elseif string.sub(start, -2, -2) == "0" then
@@ -531,6 +550,7 @@ function Element:_format_range_chicago_15(start, stop)
if #start < 3 or string.sub(start, -2) == "00" then
return self:_format_range_expanded(start, stop)
else
+ stop = self:_format_range_expanded(start, stop)
local changed_digits = self:_format_range_minimal(start, stop)
if string.sub(start, -2, -2) == "0" then
return changed_digits
@@ -551,7 +571,15 @@ function Element:_format_range_expanded(start, stop)
return string.sub(start, 1, #start - #stop) .. stop
end
+---comment
+---@param start string
+---@param stop string
+---@param threshold integer? Number of minimal digits
+---@return string
function Element:_format_range_minimal(start, stop, threshold)
+ -- util.debug(start)
+ -- util.debug(stop)
+ -- util.debug(threshold)
threshold = threshold or 1
if #start < #stop then
return stop
@@ -563,7 +591,9 @@ function Element:_format_range_minimal(start, stop, threshold)
return string.sub(stop, i)
end
end
- return string.sub(stop, -threshold)
+ local res = string.sub(stop, -threshold)
+ -- util.debug(res)
+ return res
end
element.Element = Element