• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

sile-typesetter / sile / 9507147410

13 Jun 2024 09:40PM UTC coverage: 50.521% (-18.7%) from 69.177%
9507147410

push

github

web-flow
Merge pull request #2062 from alerque/plug-fluent-leak

Link document.language setting more closely with Fluent locale

15 of 15 new or added lines in 3 files covered. (100.0%)

3244 existing lines in 65 files now uncovered.

8586 of 16995 relevant lines covered (50.52%)

4659.09 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/packages/footnotes/init.lua
UNCOV
1
local base = require("packages.base")
×
2

UNCOV
3
local package = pl.class(base)
×
UNCOV
4
package._name = "footnotes"
×
5

UNCOV
6
function package:_init (options)
×
UNCOV
7
   base._init(self)
×
UNCOV
8
   self:loadPackage("counters")
×
UNCOV
9
   self:loadPackage("raiselower")
×
UNCOV
10
   self:loadPackage("insertions")
×
UNCOV
11
   if not SILE.scratch.counters.footnotes then
×
UNCOV
12
      SILE.scratch.counters.footnote = { value = 1, display = "arabic" }
×
13
   end
UNCOV
14
   options = options or {}
×
UNCOV
15
   self.class:initInsertionClass("footnote", {
×
16
      insertInto = options.insertInto or "footnotes",
17
      stealFrom = options.stealFrom or { "content" },
18
      maxHeight = SILE.types.length("75%ph"),
19
      topBox = SILE.types.node.vglue("2ex"),
20
      interInsertionSkip = SILE.types.length("1ex"),
21
   })
22
end
23

UNCOV
24
function package:registerCommands ()
×
UNCOV
25
   self:registerCommand("footnotemark", function (_, _)
×
UNCOV
26
      SILE.call("raise", { height = "0.7ex" }, function ()
×
UNCOV
27
         SILE.call("font", { size = "1.5ex" }, function ()
×
UNCOV
28
            SILE.typesetter:typeset(self.class.packages.counters:formatCounter(SILE.scratch.counters.footnote))
×
29
         end)
30
      end)
31
   end)
32

UNCOV
33
   self:registerCommand("footnote:separator", function (_, content)
×
UNCOV
34
      SILE.settings:pushState()
×
UNCOV
35
      local material = SILE.call("vbox", {}, content)
×
UNCOV
36
      SILE.scratch.insertions.classes.footnote.topBox = material
×
UNCOV
37
      SILE.settings:popState()
×
38
   end)
39

UNCOV
40
   self:registerCommand("footnote:options", function (options, _)
×
UNCOV
41
      if options["maxHeight"] then
×
42
         SILE.scratch.insertions.classes.footnote.maxHeight = SILE.types.length(options["maxHeight"])
×
43
      end
UNCOV
44
      if options["interInsertionSkip"] then
×
UNCOV
45
         SILE.scratch.insertions.classes.footnote.interInsertionSkip = SILE.types.length(options["interInsertionSkip"])
×
46
      end
47
   end)
48

UNCOV
49
   self:registerCommand("footnote", function (options, content)
×
UNCOV
50
      SILE.call("footnotemark")
×
UNCOV
51
      local opts = SILE.scratch.insertions.classes.footnote or {}
×
UNCOV
52
      local frame = opts.insertInto and SILE.getFrame(opts.insertInto.frame)
×
UNCOV
53
      local oldGetTargetLength = SILE.typesetter.getTargetLength
×
UNCOV
54
      local oldFrame = SILE.typesetter.frame
×
UNCOV
55
      SILE.typesetter.getTargetLength = function ()
×
UNCOV
56
         return SILE.types.length(0xFFFFFF)
×
57
      end
UNCOV
58
      SILE.settings:pushState()
×
59
      -- Restore the settings to the top of the queue, which should be the document #986
UNCOV
60
      SILE.settings:toplevelState()
×
UNCOV
61
      SILE.typesetter:initFrame(frame)
×
62

63
      -- Reset settings the document may have but should not be applied to footnotes
64
      -- See also same resets in folio package
UNCOV
65
      for _, v in ipairs({
×
66
         "current.hangAfter",
67
         "current.hangIndent",
68
         "linebreak.hangAfter",
69
         "linebreak.hangIndent",
UNCOV
70
      }) do
×
UNCOV
71
         SILE.settings:set(v, SILE.settings.defaults[v])
×
72
      end
73

74
      -- Apply the font before boxing, so relative baselineskip applies #1027
75
      local material
UNCOV
76
      SILE.call("footnote:font", {}, function ()
×
UNCOV
77
         material = SILE.call("vbox", {}, function ()
×
UNCOV
78
            SILE.call("footnote:atstart", options)
×
UNCOV
79
            SILE.call("footnote:counter", options)
×
UNCOV
80
            SILE.process(content)
×
81
         end)
82
      end)
UNCOV
83
      SILE.settings:popState()
×
UNCOV
84
      SILE.typesetter.getTargetLength = oldGetTargetLength
×
UNCOV
85
      SILE.typesetter.frame = oldFrame
×
UNCOV
86
      self.class:insert("footnote", material)
×
UNCOV
87
      SILE.scratch.counters.footnote.value = SILE.scratch.counters.footnote.value + 1
×
88
   end)
89

UNCOV
90
   self:registerCommand("footnote:font", function (_, content)
×
91
      -- The footnote frame has is settings reset to the toplevel state, so if one does
92
      -- something relative (as below), it is expected to be the main value from the
93
      -- document.
UNCOV
94
      SILE.call("font", { size = SILE.settings:get("font.size") * 0.9 }, function ()
×
UNCOV
95
         SILE.process(content)
×
96
      end)
97
   end)
98

UNCOV
99
   self:registerCommand("footnote:atstart", function (_, _) end)
×
100

UNCOV
101
   self:registerCommand("footnote:counter", function (_, _)
×
UNCOV
102
      SILE.call("noindent")
×
UNCOV
103
      SILE.typesetter:typeset(self.class.packages.counters:formatCounter(SILE.scratch.counters.footnote) .. ".")
×
UNCOV
104
      SILE.call("qquad")
×
105
   end)
106
end
107

108
package.documentation = [[
109
\begin{document}
110
The \autodoc:package{footnotes} package allows you to add footnotes to text with the \autodoc:command{\footnote} command.
111
Other commands provided by the package, not described here, take care of formatting the footnotes.
112

113
Usually, a document class is responsible for automatically loading this package.
114
Minimally, upon initialization, it needs a frame identifier for the the footnotes, and one or more frame(s) which will be reduced as the footnotes take place.
115
By default, it uses, respectively, the \code{footnotes} and \code{content} frames, which are assumed to be present in the default standard layout.
116

117
For the record, it internally relies on the \autodoc:package{insertions} package and tells it which frame should receive the footnotes that are typeset.
118
\end{document}
UNCOV
119
]]
×
120

UNCOV
121
return package
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc