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

sile-typesetter / sile / 9304060604

30 May 2024 02:07PM UTC coverage: 74.124% (-0.6%) from 74.707%
9304060604

push

github

alerque
style: Reformat Lua with stylua

8104 of 11995 new or added lines in 184 files covered. (67.56%)

15 existing lines in 11 files now uncovered.

12444 of 16788 relevant lines covered (74.12%)

7175.1 hits per line

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

0.0
/classes/docbook.lua
1
local plain = require("classes.plain")
×
2

3
local class = pl.class(plain)
×
4
class._name = "docbook"
×
5

6
SILE.scratch.docbook = {
×
7
   seclevel = 0,
8
   seccount = {},
9
}
10

11
function class:_init (options)
×
NEW
12
   plain._init(self, options)
×
NEW
13
   self:loadPackage("image")
×
NEW
14
   self:loadPackage("simpletable", {
×
15
      tableTag = "tgroup",
16
      trTag = "row",
17
      tdTag = "entry",
18
   })
NEW
19
   self:loadPackage("rules")
×
NEW
20
   self:loadPackage("verbatim")
×
NEW
21
   self:loadPackage("footnotes")
×
22
   -- SILE sensibly does not define a pixels unit because it has no meaning in its frame of reference. However the
23
   -- Docbook standard requires them and even defaults to them for bare numbers, even while warning against their use.
24
   -- Here we define a px arbitrarily to be the equivalent point unit if output was 300 DPI.
NEW
25
   SILE.units.px = {
×
26
      definition = "0.24pt",
27
   }
28
end
29

30
function class.push (t, val)
×
NEW
31
   if not SILE.scratch.docbook[t] then
×
NEW
32
      SILE.scratch.docbook[t] = {}
×
33
   end
NEW
34
   local q = SILE.scratch.docbook[t]
×
NEW
35
   q[#q + 1] = val
×
36
end
37

38
function class.pop (t)
×
NEW
39
   local q = SILE.scratch.docbook[t]
×
NEW
40
   q[#q] = nil
×
41
end
42

43
function class.val (t)
×
NEW
44
   local q = SILE.scratch.docbook[t]
×
NEW
45
   return q[#q]
×
46
end
47

48
function class.wipe (tbl)
×
NEW
49
   while #tbl > 0 do
×
NEW
50
      tbl[#tbl] = nil
×
51
   end
52
end
53

54
class.registerCommands = function (self)
NEW
55
   plain.registerCommands(self)
×
56

57
   -- Unfinished! commands found in howto.xml example document on docbook.org
NEW
58
   self:registerCommand("acronym", function (_, content)
×
NEW
59
      SILE.process(content)
×
60
   end)
NEW
61
   self:registerCommand("alt", function (_, content)
×
NEW
62
      SILE.process(content)
×
63
   end)
NEW
64
   self:registerCommand("note", function (_, content)
×
NEW
65
      SILE.process(content)
×
66
   end)
NEW
67
   self:registerCommand("colspec", function (_, content)
×
NEW
68
      SILE.process(content)
×
69
   end)
NEW
70
   self:registerCommand("phrase", function (_, content)
×
NEW
71
      SILE.process(content)
×
72
   end)
NEW
73
   self:registerCommand("literal", function (_, content)
×
NEW
74
      SILE.process(content)
×
75
   end)
NEW
76
   self:registerCommand("docbook-section-3-title", function (_, content)
×
NEW
77
      SILE.process(content)
×
78
   end)
NEW
79
   self:registerCommand("variablelist", function (_, content)
×
NEW
80
      SILE.process(content)
×
81
   end)
NEW
82
   self:registerCommand("varlistentry", function (_, content)
×
NEW
83
      SILE.process(content)
×
84
   end)
NEW
85
   self:registerCommand("term", function (_, content)
×
NEW
86
      SILE.process(content)
×
87
   end)
NEW
88
   self:registerCommand("procedure", function (_, content)
×
NEW
89
      SILE.process(content)
×
90
   end)
NEW
91
   self:registerCommand("step", function (_, content)
×
NEW
92
      SILE.process(content)
×
93
   end)
NEW
94
   self:registerCommand("screen", function (_, content)
×
NEW
95
      SILE.process(content)
×
96
   end)
NEW
97
   self:registerCommand("command", function (_, content)
×
NEW
98
      SILE.process(content)
×
99
   end)
NEW
100
   self:registerCommand("option", function (_, content)
×
NEW
101
      SILE.process(content)
×
102
   end)
NEW
103
   self:registerCommand("package", function (_, content)
×
NEW
104
      SILE.process(content)
×
105
   end)
NEW
106
   self:registerCommand("tip", function (_, content)
×
NEW
107
      SILE.process(content)
×
108
   end)
NEW
109
   self:registerCommand("varname", function (_, content)
×
NEW
110
      SILE.process(content)
×
111
   end)
NEW
112
   self:registerCommand("qandaset", function (_, content)
×
NEW
113
      SILE.process(content)
×
114
   end)
NEW
115
   self:registerCommand("qandadiv", function (_, content)
×
NEW
116
      SILE.process(content)
×
117
   end)
NEW
118
   self:registerCommand("qandaentry", function (_, content)
×
NEW
119
      SILE.process(content)
×
120
   end)
NEW
121
   self:registerCommand("question", function (_, content)
×
NEW
122
      SILE.process(content)
×
123
   end)
NEW
124
   self:registerCommand("answer", function (_, content)
×
NEW
125
      SILE.process(content)
×
126
   end)
127

NEW
128
   self:registerCommand("docbook-line", function (_, _)
×
NEW
129
      SILE.call("medskip")
×
NEW
130
      SILE.call("hrule", { height = "0.5pt", width = "50mm" })
×
NEW
131
      SILE.call("medskip")
×
132
   end)
133

NEW
134
   self:registerCommand("docbook-sectionsfont", function (_, content)
×
NEW
135
      SILE.call("font", { family = "DejaVu Sans", style = "Condensed", weight = 800 }, content)
×
136
   end)
137

NEW
138
   self:registerCommand("docbook-ttfont", function (_, content)
×
NEW
139
      SILE.call("font", { family = "Hack", size = "2ex" }, content)
×
140
   end)
141

NEW
142
   self:registerCommand("docbook-article-title", function (_, content)
×
NEW
143
      SILE.call("center", {}, function ()
×
NEW
144
         SILE.call("docbook-sectionsfont", {}, function ()
×
NEW
145
            SILE.call("font", { size = "20pt" }, content)
×
146
         end)
147
      end)
NEW
148
      SILE.call("bigskip")
×
149
   end)
150

NEW
151
   self:registerCommand("docbook-section-title", function (_, content)
×
NEW
152
      SILE.call("noindent")
×
NEW
153
      SILE.call("bigskip")
×
NEW
154
      SILE.call("docbook-sectionsfont", {}, { content })
×
NEW
155
      SILE.call("bigskip")
×
156
   end)
157

NEW
158
   self:registerCommand("docbook-main-author", function (_, content)
×
NEW
159
      SILE.call("center", {}, function ()
×
NEW
160
         SILE.call("docbook-sectionsfont", {}, content)
×
161
      end)
NEW
162
      SILE.call("bigskip")
×
163
   end)
164

NEW
165
   self:registerCommand("docbook-section-1-title", function (_, content)
×
NEW
166
      SILE.call("font", { size = "16pt" }, function ()
×
NEW
167
         SILE.call("docbook-section-title", {}, content)
×
168
      end)
169
   end)
170

NEW
171
   self:registerCommand("docbook-section-2-title", function (_, content)
×
NEW
172
      SILE.call("font", { size = "12pt" }, function ()
×
NEW
173
         SILE.call("docbook-section-title", {}, content)
×
174
      end)
175
   end)
176

NEW
177
   self:registerCommand("docbook-titling", function (_, content)
×
NEW
178
      SILE.call("noindent")
×
UNCOV
179
      SILE.call("docbook-sectionsfont", {}, content)
×
180
   end)
181

NEW
182
   self:registerCommand("para", function (_, content)
×
NEW
183
      SILE.process(content)
×
NEW
184
      SILE.call("par")
×
185
   end)
186

NEW
187
   self:registerCommand("emphasis", function (_, content)
×
NEW
188
      SILE.call("em", {}, content)
×
189
   end)
190

NEW
191
   self:registerCommand("replaceable", function (_, content)
×
NEW
192
      SILE.call("em", {}, content)
×
193
   end)
194

NEW
195
   self:registerCommand("abbrev", function (_, content)
×
NEW
196
      SILE.call("font", { variant = "smallcaps" }, content)
×
197
   end)
198

NEW
199
   self:registerCommand("title", function (_, content)
×
NEW
200
      SILE.call("em", {}, content)
×
201
   end)
202

NEW
203
   self:registerCommand("personname", function (_, content)
×
NEW
204
      SILE.process(content)
×
205
   end)
206

NEW
207
   self:registerCommand("email", function (_, content)
×
NEW
208
      SILE.process(content)
×
209
   end)
210

NEW
211
   self:registerCommand("uri", function (_, content)
×
NEW
212
      SILE.call("code", {}, content)
×
213
   end)
214

NEW
215
   self:registerCommand("personblurb", function (_, content)
×
NEW
216
      SILE.call("font", { size = "2ex" }, content)
×
217
   end)
218

NEW
219
   self:registerCommand("affiliation", function (_, content)
×
NEW
220
      SILE.process(content)
×
221
   end)
222

NEW
223
   self:registerCommand("jobtitle", function (_, content)
×
NEW
224
      SILE.process(content)
×
225
   end)
226

NEW
227
   self:registerCommand("orgname", function (_, content)
×
NEW
228
      SILE.process(content)
×
229
   end)
230

NEW
231
   self:registerCommand("application", function (_, content)
×
NEW
232
      SILE.call("em", {}, content)
×
233
   end)
234

NEW
235
   self:registerCommand("menuchoice", function (_, content)
×
NEW
236
      SILE.typesetter:typeset("“")
×
NEW
237
      SILE.process(content)
×
NEW
238
      SILE.typesetter:typeset("”")
×
239
   end)
240

NEW
241
   self:registerCommand("programlisting", function (_, content)
×
NEW
242
      SILE.call("verbatim", {}, content)
×
243
   end)
244

NEW
245
   self:registerCommand("tag", function (_, content)
×
NEW
246
      SILE.call("docbook-ttfont", {}, function ()
×
NEW
247
         SILE.typesetter:typeset("<")
×
NEW
248
         SILE.process(content)
×
NEW
249
         SILE.typesetter:typeset(">")
×
250
      end)
251
   end)
252

NEW
253
   self:registerCommand("code", function (_, content)
×
NEW
254
      SILE.call("docbook-ttfont", {}, content)
×
255
   end)
256

NEW
257
   self:registerCommand("filename", function (_, content)
×
NEW
258
      SILE.call("docbook-ttfont", {}, content)
×
259
   end)
260

NEW
261
   self:registerCommand("guimenu", function (_, content)
×
NEW
262
      SILE.call("docbook-ttfont", {}, content)
×
263
   end)
264

NEW
265
   self:registerCommand("guimenuitem", function (_, content)
×
NEW
266
      SILE.typesetter:typeset(" > ")
×
NEW
267
      SILE.call("docbook-ttfont", {}, content)
×
268
   end)
269

NEW
270
   self:registerCommand("guilabel", function (_, content)
×
NEW
271
      SILE.call("docbook-ttfont", {}, content)
×
272
   end)
273

NEW
274
   self:registerCommand("guibutton", function (_, content)
×
NEW
275
      SILE.call("docbook-ttfont", {}, content)
×
276
   end)
277

NEW
278
   self:registerCommand("computeroutput", function (_, content)
×
NEW
279
      SILE.call("docbook-ttfont", {}, content)
×
280
   end)
281

NEW
282
   self:registerCommand("xref", function (_, _)
×
NEW
283
      SILE.typesetter:typeset("XXX")
×
284
   end)
285

NEW
286
   self:registerCommand("citetitle", function (_, content)
×
NEW
287
      SILE.call("em", {}, content)
×
288
   end)
289

NEW
290
   self:registerCommand("quote", function (_, content)
×
NEW
291
      SILE.typesetter:typeset("“")
×
NEW
292
      SILE.process(content)
×
NEW
293
      SILE.typesetter:typeset("”")
×
294
   end)
295

NEW
296
   self:registerCommand("citation", function (_, content)
×
NEW
297
      SILE.typesetter:typeset("[")
×
NEW
298
      SILE.process(content)
×
NEW
299
      SILE.typesetter:typeset("]")
×
300
   end)
301

NEW
302
   self:registerCommand("thead", function (_, content)
×
NEW
303
      SILE.call("font", { weight = 800 }, content)
×
304
   end)
305

NEW
306
   self:registerCommand("tbody", function (_, content)
×
NEW
307
      SILE.process(content)
×
308
   end)
309

NEW
310
   self:registerCommand("mediaobject", function (_, content)
×
NEW
311
      SILE.process(content)
×
312
   end)
313

NEW
314
   self:registerCommand("imageobject", function (_, content)
×
NEW
315
      SILE.process(content)
×
316
   end)
317

NEW
318
   self:registerCommand("bibliography", function (_, content)
×
NEW
319
      SILE.call("font", { size = "16pt" }, function ()
×
NEW
320
         SILE.call("docbook-section-title", { "Bibliography" })
×
321
      end)
NEW
322
      SILE.call("par")
×
NEW
323
      SILE.call("font", { size = "2ex" }, content)
×
324
   end)
325

NEW
326
   self:registerCommand("bibliomixed", function (_, content)
×
NEW
327
      SILE.process(content)
×
NEW
328
      SILE.call("smallskip")
×
329
   end)
330

NEW
331
   self:registerCommand("bibliomisc", function (_, content)
×
NEW
332
      SILE.process(content)
×
333
   end)
334

NEW
335
   self:registerCommand("article", function (_, content)
×
NEW
336
      local info = SILE.inputter:findInTree(content, "info") or SILE.inputter:findInTree(content, "articleinfo")
×
NEW
337
      local title = SILE.inputter:findInTree(content, "title") or (info and SILE.inputter:findInTree(info, "title"))
×
NEW
338
      local author = SILE.inputter:findInTree(content, "author") or (info and SILE.inputter:findInTree(info, "author"))
×
339

NEW
340
      if title then
×
NEW
341
         SILE.call("docbook-article-title", {}, title)
×
NEW
342
         self.wipe(title)
×
343
      end
NEW
344
      if author then
×
NEW
345
         SILE.call("docbook-main-author", {}, function ()
×
NEW
346
            for _, t in ipairs(author) do
×
NEW
347
               if type(t) == "table" then
×
NEW
348
                  SILE.call(t.command, {}, t)
×
NEW
349
                  SILE.typesetter:leaveHmode()
×
NEW
350
                  SILE.call("bigskip")
×
351
               end
352
            end
353
         end)
354
      end
NEW
355
      SILE.process(content)
×
NEW
356
      SILE.typesetter:chuck()
×
357
   end)
358

NEW
359
   self:registerCommand("info", function () end)
×
360

NEW
361
   self:registerCommand("section", function (_, content)
×
NEW
362
      SILE.scratch.docbook.seclevel = SILE.scratch.docbook.seclevel + 1
×
NEW
363
      SILE.scratch.docbook.seccount[SILE.scratch.docbook.seclevel] = (
×
NEW
364
         SILE.scratch.docbook.seccount[SILE.scratch.docbook.seclevel] or 0
×
NEW
365
      ) + 1
×
NEW
366
      while #SILE.scratch.docbook.seccount > SILE.scratch.docbook.seclevel do
×
NEW
367
         SILE.scratch.docbook.seccount[#SILE.scratch.docbook.seccount] = nil
×
368
      end
NEW
369
      local title = SILE.inputter:findInTree(content, "title")
×
NEW
370
      local number = table.concat(SILE.scratch.docbook.seccount, ".")
×
NEW
371
      if title then
×
NEW
372
         SILE.call("docbook-section-" .. SILE.scratch.docbook.seclevel .. "-title", {}, function ()
×
NEW
373
            SILE.typesetter:typeset(number .. " ")
×
NEW
374
            SILE.process(title)
×
375
         end)
NEW
376
         self.wipe(title)
×
377
      end
NEW
378
      SILE.process(content)
×
NEW
379
      SILE.scratch.docbook.seclevel = SILE.scratch.docbook.seclevel - 1
×
380
   end)
381

382
   local function countedThing (thing, _, content)
NEW
383
      SILE.call("increment-counter", { id = thing })
×
NEW
384
      SILE.call("bigskip")
×
NEW
385
      SILE.call("docbook-line")
×
NEW
386
      SILE.call("docbook-titling", {}, function ()
×
NEW
387
         SILE.typesetter:typeset(thing .. " " .. self.packages.counters:formatCounter(SILE.scratch.counters[thing]))
×
NEW
388
         local t = SILE.inputter:findInTree(content, "title")
×
NEW
389
         if t then
×
NEW
390
            SILE.typesetter:typeset(": ")
×
NEW
391
            SILE.process(t)
×
NEW
392
            self.wipe(t)
×
393
         end
394
      end)
NEW
395
      SILE.call("smallskip")
×
NEW
396
      SILE.process(content)
×
NEW
397
      SILE.call("docbook-line")
×
NEW
398
      SILE.call("bigskip")
×
399
   end
400

NEW
401
   self:registerCommand("example", function (options, content)
×
NEW
402
      countedThing("Example", options, content)
×
403
   end)
404

NEW
405
   self:registerCommand("table", function (options, content)
×
NEW
406
      countedThing("Table", options, content)
×
407
   end)
NEW
408
   self:registerCommand("figure", function (options, content)
×
NEW
409
      countedThing("Figure", options, content)
×
410
   end)
411

412
   local function docmook_measurement (value)
NEW
413
      SU.dump(value)
×
NEW
414
      value = value:gsub("(%d)$", "%1px") -- bare numbers are pixels, not points
×
NEW
415
      value = value:gsub("(%%)$", "%1lw") -- percentages are relative to viewport
×
NEW
416
      return SU.cast("measurement", value)
×
417
   end
418

NEW
419
   self:registerCommand("imagedata", function (options, _)
×
NEW
420
      local width = options.width and docmook_measurement(options.width)
×
NEW
421
      SILE.call("img", { src = options.fileref, width = width })
×
422
   end)
423

NEW
424
   self:registerCommand("itemizedlist", function (_, content)
×
NEW
425
      self.push("list", { type = "itemized" })
×
NEW
426
      SILE.call("medskip")
×
427
      -- Indentation
NEW
428
      SILE.process(content)
×
NEW
429
      SILE.call("medskip")
×
NEW
430
      self.pop("list")
×
431
   end)
432

NEW
433
   self:registerCommand("orderedlist", function (_, content)
×
NEW
434
      self.push("list", { type = "ordered", ctr = 1 })
×
NEW
435
      SILE.call("medskip")
×
436
      -- Indentation
NEW
437
      SILE.process(content)
×
NEW
438
      SILE.call("medskip")
×
NEW
439
      self.pop("list")
×
440
   end)
441

NEW
442
   self:registerCommand("listitem", function (_, content)
×
NEW
443
      local ctx = self.val("list")
×
NEW
444
      if ctx and ctx.type == "ordered" then
×
NEW
445
         SILE.typesetter:typeset(ctx.ctr .. ". ")
×
NEW
446
         ctx.ctr = ctx.ctr + 1
×
NEW
447
      elseif ctx and ctx.type == "itemized" then
×
NEW
448
         SILE.typesetter:typeset("• ")
×
449
      -- elseif ctx and ctx.type == "" then
450
      --   -- Other types?
451
      else
NEW
452
         return SU.warn("Listitem in outer space")
×
453
      end
NEW
454
      SILE.call("noindent")
×
NEW
455
      for _ = 1, #ctx - 1 do
×
NEW
456
         SILE.call("qquad")
×
457
      end -- Setting lskip better?
NEW
458
      SILE.process(content)
×
NEW
459
      SILE.call("medskip")
×
460
   end)
461

NEW
462
   self:registerCommand("link", function (options, content)
×
NEW
463
      SILE.process(content)
×
NEW
464
      if options["xl:href"] then
×
NEW
465
         SILE.typesetter:typeset(" (")
×
NEW
466
         SILE.call("code", {}, { options["xl:href"] })
×
NEW
467
         SILE.typesetter:typeset(")")
×
468
      end
469
   end)
470
end
471

472
return class
×
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