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

sile-typesetter / sile / 14284237390

05 Apr 2025 05:33PM UTC coverage: 63.158% (+31.8%) from 31.375%
14284237390

push

github

web-flow
Merge pull request #2248 from alerque/class-warfare

Normalize module layout across all module types

257 of 350 new or added lines in 14 files covered. (73.43%)

71 existing lines in 11 files now uncovered.

13670 of 21644 relevant lines covered (63.16%)

3070.68 hits per line

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

98.51
/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
-- Lua loader modifications to support more resource types and module layouts
11
require("core.loaders")
224✔
12

13
-- Placeholder for SILE internals table
14
SILE = {}
224✔
15

16
--- Fields
17
-- @section fields
18

19
--- Machine friendly short-form version.
20
-- Semver, prefixed with "v", possible postfixed with ".r" followed by VCS version information.
21
-- @string version
22
SILE.version = require("core.version")
224✔
23

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

33
-- Initialize Lua environment and global utilities
34

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

40
--- Whether or not Lua VM is a JIT compiler.
41
-- @boolean lua_isjit
42
-- luacheck: ignore jit
43
SILE.lua_isjit = type(jit) == "table"
224✔
44

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

50
--- Default to verbose mode, can be changed from the CLI or by libraries
51
--- @boolean quiet
52
SILE.quiet = false
224✔
53

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

59
--- Modules
60
-- @section modules
61

62
--- Utilities module, typically accessed via `SU` alias.
63
-- @see SU
64
SILE.utilities = require("core.utilities")
224✔
65
SU = SILE.utilities -- regrettable global alias
224✔
66

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

72
--- Data tables
73
--- @section data
74

75
--- Stash of all Lua functions used to power typesetter commands.
76
-- @table Commands
77
SILE.Commands = {}
224✔
78

79
--- Short usage messages corresponding to typesetter commands.
80
-- @table Help
81
SILE.Help = {}
224✔
82

83
--- List of currently enabled debug flags.
84
-- E.g. `{ typesetter = true, frames, true }`.
85
-- @table debugFlags
86
SILE.debugFlags = {}
224✔
87

88
SILE.nodeMakers = {}
224✔
89
SILE.tokenizers = {}
224✔
90
SILE.status = {}
224✔
91

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

101
--- Data storage for typesetter, frame, and class information.
102
-- Current document class instances, node queues, and other "hot" data can be found here. As with `SILE.scratch`
103
-- everything in here probably belongs elsewhere, but for now it is what it is.
104
-- @table documentState
105
-- @tfield table documentClass The instantiated document processing class.
106
-- @tfield table thisPageTemplate The frameset used for the current page.
107
-- @tfield table paperSize The current paper size.
108
-- @tfield table orgPaperSize The original paper size if the current one is modified via packages.
109
SILE.documentState = {}
224✔
110

111
--- Callback functions for handling types of raw content.
112
-- All registered handlers for raw content blocks have an entry in this table with the type as the key and the
113
-- processing function as the value.
114
-- @ table rawHandlers
115
SILE.rawHandlers = {}
224✔
116

117
--- User input
118
-- @section input
119

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

147
-- Internal libraries that are idempotent and return classes that need instantiation
148
SILE.inputters = SILE.utilities._module_loader("inputters")
448✔
149
SILE.shapers = SILE.utilities._module_loader("shapers")
448✔
150
SILE.outputters = SILE.utilities._module_loader("outputters")
448✔
151
SILE.classes = SILE.utilities._module_loader("classes")
448✔
152
SILE.packages = SILE.utilities._module_loader("packages")
448✔
153
SILE.typesetters = SILE.utilities._module_loader("typesetters")
448✔
154
SILE.pagebuilders = SILE.utilities._module_loader("pagebuilders")
448✔
155
SILE.types = SILE.utilities._module_loader("types")
448✔
156

157
-- Internal libraries that don't try to use anything on load, only provide something
158
SILE.parserBits = require("core.parserbits")
224✔
159
SILE.frameParser = require("core.frameparser")
224✔
160
SILE.fontManager = require("core.fontmanager")
223✔
161
SILE.papersize = require("core.papersize")
223✔
162

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

168
--- Core functions
169
-- @section functions
170

171
--- Initialize a SILE instance.
172
-- Presumes CLI args have already been processed and/or library inputs are set.
173
--
174
-- 1. If no backend has been loaded already (e.g. via `--use`) then assumes *libtexpdf*.
175
-- 2. Loads and instantiates a shaper and outputter module appropriate for the chosen backend.
176
-- 3. Instantiates a pagebuilder.
177
-- 4. Starts a Lua profiler if the profile debug flag is set.
178
-- 5. Instantiates a dependency tracker if we've been asked to write make dependencies.
179
-- 6. 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
223✔
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")
223✔
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
223✔
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
223✔
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
223✔
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
223✔
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
223✔
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
223✔
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
223✔
237

238
--- (Deprecated) Register a function as a SILE command.
239
-- Takes any Lua function and registers it for use as a SILE command (which will in turn be used to process any content
240
-- nodes identified with the command name.
241
--
242
-- Note that alternative versions of this action are available as methods on document classes and packages. Those
243
-- interfaces should be preferred to this global one.
244
-- @tparam string name Name of cammand to register.
245
-- @tparam function func Callback function to use as command handler.
246
-- @tparam[opt] nil|string help User friendly short usage string for use in error messages, documentation, etc.
247
-- @tparam[opt] nil|string pack Information identifying the module registering the command for use in error and usage
248
-- messages. Usually auto-detected.
249
-- @see SILE.classes:registerCommand
250
-- @see SILE.packages:registerCommand
251
SILE.registerCommand = require("core.misc").registerCommand
223✔
252

253
--- Wrap an existing command with new default options.
254
-- Modifies an already registered SILE command with a new table of options to be used as default values any time it is
255
-- called. Calling options still take precedence.
256
-- @tparam string command Name of command to overwrite.
257
-- @tparam table options Options to set as updated defaults.
258
SILE.setCommandDefaults = require("core.misc").setCommandDefaults
223✔
259

260
-- TODO: Move to new table entry handler in types.unit
261
SILE.registerUnit = require("core.misc").registerUnit
223✔
262

263
SILE.paperSizeParser = require("core.misc").paperSizeParser
223✔
264

265
--- Finalize document processing
266
-- Signals that all the `SILE.process()` calls have been made and SILE should move on to finish up the output
267
--
268
-- 1. Tells the document class to run its `:finish()` method. This method is typically responsible for calling the
269
-- `:finish()` method of the outputter module in the appropriate sequence.
270
-- 2. Closes out anything in active memory we don't need like font instances.
271
-- 3. Evaluate any snippets in SILE.input.evalAfter table.
272
-- 4. Stops logging dependencies and writes them to a makedepends file if requested.
273
-- 5. Close out the Lua profiler if it was running.
274
-- 6. Output version information if versions debug flag is set.
275
SILE.finish = require("core.init").finish
223✔
276

277
-- Internal libraries that return classes, but we have no subclasses an only ever use one instantiation of the base
278
SILE.traceStack = require("core.tracestack")()
446✔
279
SILE.settings = require("core.settings")()
446✔
280

281
-- Internal libraries that run core SILE functions on load
282
require("core.hyphenator-liang")
223✔
283
require("core.languages")
223✔
284
SILE.linebreak = require("core.break")
223✔
285
require("core.frame")
223✔
286
SILE.font = require("core.font")
223✔
287

288
return SILE
223✔
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