summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/scripts/citation-style-language/citeproc-node-layout.lua
blob: 168f923b0850c91ec606f4dbd57fb2d4a48ceba3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
--
-- Copyright (c) 2021-2022 Zeping Lee
-- Released under the MIT license.
-- Repository: https://github.com/zepinglee/citeproc-lua
--

local layout = {}

local Element = require("citeproc-element").Element
local SeqIr = require("citeproc-ir-node").SeqIr
local util = require("citeproc-util")


local Layout = Element:derive("layout")

function Layout:from_node(node)
  local o = Layout:new()
  o:set_affixes_attributes(node)
  o:set_formatting_attributes(node)
  o:get_delimiter_attribute(node)

  o:process_children_nodes(node)

  return o
end

function Layout:build_ir(engine, state, context)
  local ir = self:build_children_ir(engine, state, context)
  if not ir then
    return nil
  end
  if context.in_bibliography then
    ir.delimiter = self.delimiter

    -- Move affixes of `bibliography > layout` into the right-inline element
    -- bugreports_SmallCapsEscape.txt
    local has_right_inline = false
    if self.affixes or self.formatting then
      for i, child_ir in ipairs(ir.children) do
        if child_ir.display == "right-inline" then
          has_right_inline = true
          local right_inline_with_affixes = SeqIr:new({child_ir}, self)
          right_inline_with_affixes.affixes = util.clone(self.affixes)
          right_inline_with_affixes.formatting = util.clone(self.formatting)
          child_ir.display = nil
          right_inline_with_affixes.display = "right-inline"
          ir.children[i] = right_inline_with_affixes
          break
        end
      end
    end

    if not has_right_inline then
      ir.affixes = util.clone(self.affixes)
      ir.formatting = util.clone(self.formatting)
    end
  end
  return ir
end


layout.Layout = Layout

return layout