diff options
Diffstat (limited to 'biblio/citation-style-language/citeproc-output.lua')
-rw-r--r-- | biblio/citation-style-language/citeproc-output.lua | 43 |
1 files changed, 31 insertions, 12 deletions
diff --git a/biblio/citation-style-language/citeproc-output.lua b/biblio/citation-style-language/citeproc-output.lua index aa1a733c3e..7115fe2acd 100644 --- a/biblio/citation-style-language/citeproc-output.lua +++ b/biblio/citation-style-language/citeproc-output.lua @@ -9,20 +9,25 @@ local output_module = {} local uni_utf8 local unicode local dom +local ir_node local util if kpse then uni_utf8 = require("unicode").utf8 unicode = require("citeproc-unicode") dom = require("luaxml-domobject") + ir_node = require("citeproc-ir-node") util = require("citeproc-util") else uni_utf8 = require("lua-utf8") unicode = require("citeproc.unicode") dom = require("citeproc.luaxml.domobject") + ir_node = require("citeproc.ir-node") util = require("citeproc.util") end +local GroupVar = ir_node.GroupVar + local LocalizedQuotes = { outer_open = util.unicode['left double quotation mark'], @@ -246,7 +251,7 @@ function CiteInline:new(inlines, cite_item) end -function InlineElement:parse(text, context) +function InlineElement:parse(text, context, is_external) local text_type = type(text) local inlines if text_type == "table" then @@ -255,7 +260,7 @@ function InlineElement:parse(text, context) elseif text_type == "string" then -- String with HTML-like formatting tags -- util.debug(text) - inlines = self:parse_html_tags(text, context) + inlines = self:parse_html_tags(text, context, is_external) -- util.debug(inlines) elseif text_type == "number" then inlines = {PlainText:new(tostring(text))} @@ -333,7 +338,7 @@ function InlineElement:parse_csl_rich_text(text) end -- TODO: Rewrite with lpeg -function InlineElement:parse_html_tags(str, context) +function InlineElement:parse_html_tags(str, context, is_external) -- Return a list of inlines -- if type(str) ~= "string" then -- print(debug.traceback()) @@ -350,7 +355,7 @@ function InlineElement:parse_html_tags(str, context) inlines = {el} end - inlines = InlineElement:parse_quotes(inlines, context) + inlines = InlineElement:parse_quotes(inlines, context, is_external) return inlines end @@ -400,7 +405,7 @@ function InlineElement:from_node(node) return InlineElement:new(inlines) end -function InlineElement:parse_quotes(inlines, context) +function InlineElement:parse_quotes(inlines, context, is_external) local quote_fragments = InlineElement:get_quote_fragments(inlines) -- util.debug(quote_fragments) @@ -419,7 +424,7 @@ function InlineElement:parse_quotes(inlines, context) if type(fragment) == "table" then if fragment.inlines then - fragment.inlines = self:parse_quotes(fragment.inlines, context) + fragment.inlines = self:parse_quotes(fragment.inlines, context, is_external) end table.insert(top_text_list, fragment) @@ -462,6 +467,14 @@ function InlineElement:parse_quotes(inlines, context) (quote == util.unicode["right-pointing double angle quotation mark"] and top_quote == util.unicode["left-pointing double angle quotation mark"]) then table.remove(quote_stack) + if is_external then + -- The text is from prefix or suffix of citationItem. + -- See flipflop_LeadingMarkupWithApostrophe.txt + localized_quotes.outer_open = top_quote + localized_quotes.outer_close = quote + localized_quotes.inner_open = top_quote + localized_quotes.inner_close = quote + end local quoted = Quoted:new(top_text_list, localized_quotes) table.remove(text_stack) table.insert(text_stack[#text_stack], quoted) @@ -652,7 +665,7 @@ function OutputFormat:new(format_name) end function OutputFormat:flatten_ir(ir, override_delim) - if self.group_var == "missing" or self.collapse_suppressed then + if self.group_var == GroupVar.Missing or self.collapse_suppressed then return {} end local inlines = {} @@ -680,7 +693,7 @@ function OutputFormat:flatten_seq_ir(ir, override_delim) end for _, child in ipairs(ir.children) do - if child.group_var ~= "missing" and not child.collapse_suppressed then + if child.group_var ~= GroupVar.Missing and not child.collapse_suppressed then local child_inlines = self:flatten_ir(child, delimiter) if #child_inlines > 0 then table.insert(inlines_list, child_inlines) @@ -1847,12 +1860,18 @@ function DisamStringFormat:output(inlines, context) end function DisamStringFormat:flatten_ir(ir) - if self.group_var == "missing" then + if self.group_var == GroupVar.Missing then return {} end local inlines if ir._type == "SeqIr" or ir._type == "NameIr" then - inlines = self:flatten_seq_ir(ir) + if ir._element and ir._element.variable == "accessed" then + -- Accessed isn't really part of a reference -- it doesn't help disambiguating one from + -- another. So we will ignore it. Works for, e.g., date_YearSuffixImplicitWithNoDate.txt + inlines = {} + else + inlines = self:flatten_seq_ir(ir) + end elseif ir._type == "YearSuffix" then -- Don't include year-suffix in disambiguation inlines = {} @@ -1872,7 +1891,7 @@ function DisamStringFormat:flatten_seq_ir(ir) end local inlines_list = {} for _, child in ipairs(ir.children) do - if child.group_var ~= "missing" then + if child.group_var == GroupVar.Important or child.group_var == GroupVar.Plain then -- and not child.collapse_suppressed -- Suppressed irs are stil kept in the DisamStringFormat table.insert(inlines_list, self:flatten_ir(child)) @@ -1885,7 +1904,7 @@ function DisamStringFormat:flatten_seq_ir(ir) inlines = self:with_display(inlines, ir.display); -- -- A citation layout - -- if ir._element == "layout" and ir.cite_item then + -- if ir._element_name == "layout" and ir.cite_item then -- inlines = {CiteInline:new(inlines, ir.cite_item)} -- end |