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

sile-typesetter / sile / 14860011647

06 May 2025 12:44PM UTC coverage: 67.057% (+32.5%) from 34.559%
14860011647

push

github

alerque
chore(typesetters): Fixup access to class from typesetter functions

7 of 7 new or added lines in 2 files covered. (100.0%)

1344 existing lines in 103 files now uncovered.

14880 of 22190 relevant lines covered (67.06%)

11549.16 hits per line

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

98.36
/core/sile.lua
1
--- The core SILE library.
2
-- Depending on how SILE was loaded, everything in here will probably be available under a top level `SILE` global. Note
3
-- that an additional global `SU` is typically available as an alias to `SILE.utilities`. Also some 3rd party Lua
4
-- libraries are always made available in the global scope, see `globals`.
5
-- @module SILE
6

7
-- Placeholder for 3rd party Lua libraries SILE always provides as globals
8
require("core.globals")
1✔
9

10
-- Placeholder for SILE internals table
11
SILE = {}
303✔
12

13
--- Fields
14
-- @section fields
15

16
--- Machine friendly short-form version.
17
-- Semver, prefixed with "v", possible postfixed with ".r" followed by VCS version information.
18
-- @string version
19
SILE.version = require("core.version")
303✔
20

21
--- Status information about what options SILE was compiled with.
22
-- @table SILE.features
23
-- @tfield boolean appkit
24
-- @tfield boolean font_variations
25
-- @tfield boolean fontconfig
26
-- @tfield boolean harfbuzz
27
-- @tfield boolean icu
28
SILE.features = require("core.features")
303✔
29

30
-- Initialize Lua environment and global utilities
31

32
--- ABI version of Lua VM.
33
-- For example may be `"5.1"` or `"5.4"` or others. Note that the ABI version for most LuaJIT implementations is 5.1.
34
-- @string lua_version
35
SILE.lua_version = _VERSION:sub(-3)
606✔
36

37
--- Whether or not Lua VM is a JIT compiler.
38
-- @boolean lua_isjit
39
-- luacheck: ignore jit
40
SILE.lua_isjit = type(jit) == "table"
303✔
41

42
--- User friendly long-form version string.
43
-- For example may be "SILE v0.14.17 (Lua 5.4)".
44
-- @string full_version
45
SILE.full_version = string.format("SILE %s (%s)", SILE.version, SILE.lua_isjit and jit.version or _VERSION)
303✔
46

47
--- Default to verbose mode, can be changed from the CLI or by libraries
48
--- @boolean quiet
49
SILE.quiet = false
303✔
50

51
-- Backport of lots of Lua 5.3 features to Lua 5.[12]
52
if not SILE.lua_isjit and SILE.lua_version < "5.3" then
303✔
UNCOV
53
   require("compat53")
×
54
end
55

56
--- Modules
57
-- @section modules
58

59
--- Utilities module, typically accessed via `SU` alias.
60
-- @see SU
61
SILE.utilities = require("core.utilities")
303✔
62
SU = SILE.utilities -- regrettable global alias
303✔
63

64
-- For warnings and shims scheduled for removal that are easier to keep track
65
-- of when they are not spread across so many locations...
66
-- Loaded early to make it easier to manage migrations in core code.
67
require("core.deprecations")
303✔
68

69
--- Data tables
70
--- @section data
71

72
--- List of currently enabled debug flags.
73
-- E.g. `{ typesetter = true, frames, true }`.
74
-- @table debugFlags
75
SILE.debugFlags = {}
303✔
76

77
-- Internal flags used to support integration tests, etc.
78
SILE._status = {}
303✔
79

80
--- The wild-west of stash stuff.
81
-- No rules, just right (or usually wrong). Everything in here *should* be somewhere else, but lots of early SILE code
82
-- relied on this as a global key/value store for various class, document, and package values. Since v0.14.0 with many
83
-- core SILE components being instances of classes –and especially with each package having it's own variable namespace–
84
-- there are almost always better places for things. This scratch space will eventually be completely deprecated, so
85
-- don't put anything new in here and only use things in it if there are no other current alternatives.
86
-- @table scratch
87
SILE.scratch = {}
303✔
88

89
--- Data storage for typesetter, frame, and class information.
90
-- Current document class instances, node queues, and other "hot" data can be found here. As with `SILE.scratch`
91
-- everything in here probably belongs elsewhere, but for now it is what it is.
92
-- @table documentState
93
-- @tfield table documentClass The instantiated document processing class.
94
-- @tfield table thisPageTemplate The frameset used for the current page.
95
-- @tfield table paperSize The current paper size.
96
-- @tfield table orgPaperSize The original paper size if the current one is modified via packages.
97
SILE.documentState = {}
303✔
98

99
--- Callback functions for handling types of raw content.
100
-- All registered handlers for raw content blocks have an entry in this table with the type as the key and the
101
-- processing function as the value.
102
-- @ table rawHandlers
103
SILE.rawHandlers = {}
303✔
104

105
--- User input
106
-- @section input
107

108
--- All user-provided input collected before beginning document processing.
109
-- User input values, currently from CLI options, potentially all the inuts
110
-- needed for a user to use a SILE-as-a-library version to produce documents
111
-- programmatically.
112
-- @table input
113
-- @tfield table filenames Path names of file(s) intended for processing. Files are processed in the order provided.
114
-- File types may be mixed of any formaat for which SILE has an inputter module.
115
-- @tfield table evaluates List of strings to be evaluated as Lua code snippets *before* processing inputs.
116
-- @tfield table evaluateAfters List of strings to be evaluated as Lua code snippets *after* processing inputs.
117
-- @tfield table uses List of strings specifying module names (and optionally optionns) for modules to load *before*
118
-- processing inputs. For example this accommodates loading inputter modules before any input of that type is encountered.
119
-- Additionally it can be used to process a document using a document class *other than* the one specified in the
120
-- document itself. Document class modules loaded here are instantiated after load, meaning the document will not be
121
-- queried for a class at all.
122
-- @tfield table options Extra document class options to set or override in addition to ones found in the first input
123
-- document.
124
SILE.input = {
303✔
125
   filenames = {},
303✔
126
   evaluates = {},
303✔
127
   evaluateAfters = {},
303✔
128
   luarocksTrees = {},
303✔
129
   uses = {},
303✔
130
   options = {},
303✔
131
   preambles = {}, -- deprecated, undocumented
303✔
132
   postambles = {}, -- deprecated, undocumented
303✔
133
}
303✔
134

135
-- Internal libraries that don't try to use anything on load, only provide something
136
SILE.parserBits = require("core.parserbits")
303✔
137
SILE.frameParser = require("core.frameparser")
303✔
138
SILE.papersize = require("core.papersize")
302✔
139

140
-- Helper function thata creates a sparse table, then loads modules into it on demand if/when accessed.
141
local core_loader = require("core.loader")
302✔
142

143
-- Internal types may be used anywhere, and access to them is per SILE invocation.
144
SILE.types = core_loader("types")
604✔
145

146
-- Internal registries that are tracked with a single instance per SILE invocation.
147
-- These should typically accessed as attributes on other modules.
148
SILE.traceStack = require("core.tracestack")()
604✔
149
SILE.commands = require("core.commands")():forModule(SILE)
906✔
150
SILE.settings = require("core.settings")():forModule(SILE)
906✔
151

152
-- Internal modules and return classes that need instantiation (loading is idempotent)
153
SILE.inputters = core_loader("inputters")
604✔
154
SILE.shapers = core_loader("shapers")
604✔
155
SILE.fontmanagers = core_loader("fontmanagers")
604✔
156
SILE.outputters = core_loader("outputters")
604✔
157
SILE.classes = core_loader("classes")
604✔
158
SILE.packages = core_loader("packages")
604✔
159
SILE.typesetters = core_loader("typesetters")
604✔
160
SILE.linebreakers = core_loader("linebreakers")
604✔
161
SILE.pagebuilders = core_loader("pagebuilders")
604✔
162
SILE.languages = core_loader("languages")
604✔
163

164
-- NOTE:
165
-- See remainaing internal libraries loaded at the end of this file because
166
-- they run core SILE functions on load instead of waiting to be called (or
167
-- depend on others that do).
168

169
--- Core functions
170
-- @section functions
171

172
--- Initialize a SILE instance.
173
-- Presumes CLI args have already been processed and/or library inputs are set.
174
--
175
-- 1. If no backend has been loaded already (e.g. via `--use`) then assumes *libtexpdf*.
176
-- 2. Loads and instantiates a shaper and outputter module appropriate for the chosen backend.
177
-- 3. Starts a Lua profiler if the profile debug flag is set.
178
-- 4. Instantiates a dependency tracker if we've been asked to write make dependencies.
179
-- 5. Runs any code snippents passed with `--eval`.
180
--
181
-- Does not move on to processing input document(s).
182
SILE.init = require("core.init").init
302✔
183

184
--- Multi-purpose loader to load and initialize modules.
185
-- This is used to load and initialize core parts of SILE and also 3rd party modules.
186
-- Module types supported bay be an *inputter*, *outputer*, *shaper*, *typesetter*, *pagebuilder*, or *package*.
187
-- @tparam string|table module The module spec name to load (dot-separated, e.g. `"packages.lorem"`) or a table with
188
--   a module that has already been loaded.
189
-- @tparam[opt] table options Startup options as key/value pairs passed to the module when initialized.
190
-- @tparam[opt=false] boolean reload whether or not to reload a module that has been loaded and initialized before.
191
SILE.use = require("core.use")
302✔
192

193
-- --- Content loader like Lua's `require()` but with special path handling for loading SILE resource files.
194
-- -- Used for example by commands that load data via a `src=file.name` option.
195
-- -- @tparam string dependency Lua spec
196
SILE.require = require("core.require").require
302✔
197

198
--- Process content.
199
-- This is the main 'action' SILE does. Once input files are parsed into an abstract syntax tree, then we recursively
200
-- iterate through the tree handling each item in the order encountered.
201
-- @tparam table ast SILE content in abstract syntax tree format (a table of strings, functions, or more AST trees).
202
SILE.process = require("core.process").process
302✔
203

204
--- Process an input string.
205
-- First converts the string to an AST, then runs `process` on it.
206
-- @tparam string doc Input string to be converted to SILE content.
207
-- @tparam[opt] nil|string format The name of the formatter. If nil, defaults to using each intputter's auto detection.
208
-- @tparam[opt] nil|string filename Pseudo filename to identify the content with, useful for error messages stack traces.
209
-- @tparam[opt] nil|table options Options to pass to the inputter instance when instantiated.
210
SILE.processString = require("core.process").processString
302✔
211

212
--- Process an input file
213
-- Opens a file, converts the contents to an AST, then runs `process` on it.
214
-- Roughly equivalent to listing the file as an input, but easier to embed in code.
215
-- @tparam string filename Path of file to open string to be converted to SILE content.
216
-- @tparam[opt] nil|string format The name of the formatter. If nil, defaults to using each intputter's auto detection.
217
-- @tparam[opt] nil|table options Options to pass to the inputter instance when instantiated.
218
SILE.processFile = require("core.process").processFile
302✔
219

220
-- TODO: this probably needs deprecating, moved here just to get out of the way so
221
-- typesetters classing works as expected
222
SILE.typesetNaturally = require("core.misc").typesetNaturally
302✔
223

224
--- Resolve relative file paths to identify absolute resources locations.
225
-- Makes it possible to load resources from relative paths, relative to a document or project or SILE itself.
226
-- @tparam string filename Name of file to find using the same order of precedence logic in `require()`.
227
-- @tparam[opt] nil|string pathprefix Optional prefix in which to look for if the file isn't found otherwise.
228
SILE.resolveFile = require("core.require").resolveFile
302✔
229

230
--- Execute a registered SILE command.
231
-- Uses a function previously registered by any modules explicitly loaded by the user at runtime via `--use`, the SILE
232
-- core, the document class, or any loaded package.
233
-- @tparam string command Command name.
234
-- @tparam[opt={}] nil|table options Options to pass to the command.
235
-- @tparam[opt] nil|table content Any valid AST node to be processed by the command.
236
SILE.call = require("core.misc").call
302✔
237

238
-- TODO: Move to new table entry handler in types.unit
239
SILE.registerUnit = require("core.misc").registerUnit
302✔
240

241
SILE.paperSizeParser = require("core.misc").paperSizeParser
302✔
242

243
--- Finalize document processing
244
-- Signals that all the `SILE.process()` calls have been made and SILE should move on to finish up the output
245
--
246
-- 1. Tells the document class to run its `:finish()` method. This method is typically responsible for calling the
247
-- `:finish()` method of the outputter module in the appropriate sequence.
248
-- 2. Closes out anything in active memory we don't need like font instances.
249
-- 3. Evaluate any snippets in SILE.input.evalAfter table.
250
-- 4. Stops logging dependencies and writes them to a makedepends file if requested.
251
-- 5. Close out the Lua profiler if it was running.
252
-- 6. Output version information if versions debug flag is set.
253
SILE.finish = require("core.init").finish
302✔
254

255
-- Internal libraries that run core SILE functions on load
256
require("core.frame")
302✔
257
SILE.font = require("core.font")
302✔
258

259
return SILE
302✔
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

© 2026 Coveralls, Inc