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

sile-typesetter / sile / 14958605596

11 May 2025 06:34PM UTC coverage: 31.311% (-25.4%) from 56.689%
14958605596

push

github

web-flow
Merge 3e53926d5 into 443551a3e

6301 of 20124 relevant lines covered (31.31%)

4203.99 hits per line

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

64.52
/packages/infonode/init.lua
1
local base = require("packages.base")
2✔
2

3
local package = pl.class(base)
2✔
4
package._name = "infonode"
2✔
5

6
-- Info nodes are used to store information about what actually ends up on which page.
7
-- Index terms are an obvious use for this, as well as anything where you wanted to
8
-- know where something had ended up after the page builder had broken the page.
9
-- Check out SILE.scratch.info.thispage in your end-of-page routine and see what nodes
10
-- are there.
11

12
local _info = pl.class(SILE.types.node.zerohbox)
2✔
13
_info.type = "info"
2✔
14

15
function _info:__tostring ()
2✔
16
   return "I<" .. self.category .. "|" .. tostring(self.value) .. ">"
×
17
end
18

19
function _info:outputYourself ()
2✔
20
   if not SILE.scratch.info.thispage[self.category] then
×
21
      SILE.scratch.info.thispage[self.category] = { self.value }
×
22
   else
23
      local i = #SILE.scratch.info.thispage[self.category] + 1
×
24
      SILE.scratch.info.thispage[self.category][i] = self.value
×
25
   end
26
end
27

28
local function newPageInfo (_)
29
   SILE.scratch.info = { thispage = {} }
15✔
30
end
31

32
local _deprecate = [[
33
   Directly calling info node handling functions is no longer necessary. All the
34
   SILE core classes and anything inheriting from them will take care of this
35
   automatically using hooks. Custom classes that override the class:endPage()
36
   function may need to handle this in other ways. By calling this hook directly
37
   you are likely causing it to run twice and duplicate entries.
38
]]
2✔
39

40
function package:_init ()
2✔
41
   base._init(self)
2✔
42
   if not SILE.scratch.info then
2✔
43
      SILE.scratch.info = { thispage = {} }
2✔
44
   end
45
   self.class:registerHook("newpage", newPageInfo)
2✔
46
   self:deprecatedExport("newPageInfo", function ()
4✔
47
      SU.deprecated("class:newPageInfo", nil, "0.13.0", "0.15.0", _deprecate)
×
48
   end)
49
end
50

51
function package:registerCommands ()
2✔
52
   self:registerCommand("info", function (options, _)
4✔
53
      SU.required(options, "category", "info node")
×
54
      SU.required(options, "value", "info node")
×
55
      table.insert(
×
56
         SILE.typesetter.state.nodes,
×
57
         _info({
×
58
            category = options.category,
59
            value = options.value,
60
         })
61
      )
62
   end, "Inserts an info node onto the current page")
2✔
63
end
64

65
package.documentation = [[
66
\begin{document}
67
\autodoc:note{This package is only for class designers.}
68

69
While typesetting a document, SILE first breaks a paragraph into lines, then arranges lines into a page, and later outputs the page.
70
In other words, while it is looking at the text of a paragraph, it is not clear what page the text will eventually end up on.
71
This makes it difficult to produce indexes, tables of contents, and so on, where one needs to know the page number for a particular element.
72

73
To get around this problem, the \autodoc:package{infonode} package allows you to insert \em{information nodes} into the text stream; when a page is outputted, these nodes are collected into a list, and a class’s output routine can examine this list to determine which nodes fell on a particular page.
74
\autodoc:package{infonode} provides the \autodoc:command{\info} command to put an information node into the text stream; it has two required parameters, \autodoc:parameter{category=<name>} and \autodoc:parameter{value=<any object>}.
75
Categories are used to group similar sets of node together.
76

77
As an example, when typesetting a Bible, you may wish to display which range of verses are on each page as a running header.
78
During the command which starts a new verse, you would insert an information node with the verse reference:
79

80
\begin[type=autodoc:codeblock]{raw}
81
SILE.call("info", { category = "references", value = ref }, {})
82
\end{raw}
83

84
During the \code{endPage} method which is called at the end of every page, we look at the list of “references” information nodes:
85

86
\begin[type=autodoc:codeblock]{raw}
87
local refs = SILE.scratch.info.thispage.references
88
local runningHead = SILE.shaper.shape(refs[1] .. " - " .. refs[#refs])
89
SILE.typesetNaturally(rhFrame, runningHead);
90
\end{raw}
91
\end{document}
92
]]
2✔
93

94
return package
2✔
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