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

sile-typesetter / sile / 9304049654

30 May 2024 02:12PM UTC coverage: 60.021% (-14.7%) from 74.707%
9304049654

push

github

web-flow
Merge 1a26b4f22 into a1fd105f8

6743 of 12900 new or added lines in 186 files covered. (52.27%)

347 existing lines in 49 files now uncovered.

10311 of 17179 relevant lines covered (60.02%)

3307.34 hits per line

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

0.0
/classes/docbook.lua
1
--- docbook document class.
2
-- @use classes.docbook
3

UNCOV
4
local plain = require("classes.plain")
×
5

6
local class = pl.class(plain)
×
7
class._name = "docbook"
×
8

9
SILE.scratch.docbook = {
×
10
   seclevel = 0,
11
   seccount = {},
12
}
13

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

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

41
function class.pop (t)
×
NEW
42
   local q = SILE.scratch.docbook[t]
×
NEW
43
   q[#q] = nil
×
44
end
45

46
function class.val (t)
×
NEW
47
   local q = SILE.scratch.docbook[t]
×
NEW
48
   return q[#q]
×
49
end
50

51
function class.wipe (tbl)
×
NEW
52
   while #tbl > 0 do
×
NEW
53
      tbl[#tbl] = nil
×
54
   end
55
end
56

57
class.registerCommands = function (self)
NEW
58
   plain.registerCommands(self)
×
59

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

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

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

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

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

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

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

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

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

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

NEW
185
   self:registerCommand("para", function (_, content)
×
NEW
186
      SILE.process(content)
×
NEW
187
      SILE.call("par")
×
188
   end)
189

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

NEW
194
   self:registerCommand("replaceable", function (_, content)
×
NEW
195
      SILE.call("em", {}, content)
×
196
   end)
197

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

NEW
202
   self:registerCommand("title", function (_, content)
×
NEW
203
      SILE.call("em", {}, content)
×
204
   end)
205

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

NEW
210
   self:registerCommand("email", function (_, content)
×
NEW
211
      SILE.process(content)
×
212
   end)
213

NEW
214
   self:registerCommand("uri", function (_, content)
×
NEW
215
      SILE.call("code", {}, content)
×
216
   end)
217

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

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

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

NEW
230
   self:registerCommand("orgname", function (_, content)
×
NEW
231
      SILE.process(content)
×
232
   end)
233

NEW
234
   self:registerCommand("application", function (_, content)
×
NEW
235
      SILE.call("em", {}, content)
×
236
   end)
237

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

NEW
244
   self:registerCommand("programlisting", function (_, content)
×
NEW
245
      SILE.call("verbatim", {}, content)
×
246
   end)
247

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

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

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

NEW
264
   self:registerCommand("guimenu", function (_, content)
×
NEW
265
      SILE.call("docbook-ttfont", {}, content)
×
266
   end)
267

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

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

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

NEW
281
   self:registerCommand("computeroutput", function (_, content)
×
NEW
282
      SILE.call("docbook-ttfont", {}, content)
×
283
   end)
284

NEW
285
   self:registerCommand("xref", function (_, _)
×
NEW
286
      SILE.typesetter:typeset("XXX")
×
287
   end)
288

NEW
289
   self:registerCommand("citetitle", function (_, content)
×
NEW
290
      SILE.call("em", {}, content)
×
291
   end)
292

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

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

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

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

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

NEW
317
   self:registerCommand("imageobject", function (_, content)
×
NEW
318
      SILE.process(content)
×
319
   end)
320

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

NEW
329
   self:registerCommand("bibliomixed", function (_, content)
×
NEW
330
      SILE.process(content)
×
NEW
331
      SILE.call("smallskip")
×
332
   end)
333

NEW
334
   self:registerCommand("bibliomisc", function (_, content)
×
NEW
335
      SILE.process(content)
×
336
   end)
337

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

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

NEW
362
   self:registerCommand("info", function () end)
×
363

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

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

NEW
404
   self:registerCommand("example", function (options, content)
×
NEW
405
      countedThing("Example", options, content)
×
406
   end)
407

NEW
408
   self:registerCommand("table", function (options, content)
×
NEW
409
      countedThing("Table", options, content)
×
410
   end)
NEW
411
   self:registerCommand("figure", function (options, content)
×
NEW
412
      countedThing("Figure", options, content)
×
413
   end)
414

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

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

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

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

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

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

475
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

© 2026 Coveralls, Inc