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

sile-typesetter / sile / 9400953783

06 Jun 2024 12:32PM UTC coverage: 62.819% (-11.3%) from 74.124%
9400953783

push

github

alerque
Merge branch 'develop'

1752 of 2644 new or added lines in 109 files covered. (66.26%)

2019 existing lines in 84 files now uncovered.

10830 of 17240 relevant lines covered (62.82%)

3306.33 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)
×
15
   plain._init(self, options)
×
16
   self:loadPackage("image")
×
17
   self:loadPackage("simpletable", {
×
18
      tableTag = "tgroup",
19
      trTag = "row",
20
      tdTag = "entry",
21
   })
22
   self:loadPackage("rules")
×
23
   self:loadPackage("verbatim")
×
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)
×
34
   if not SILE.scratch.docbook[t] then
×
35
      SILE.scratch.docbook[t] = {}
×
36
   end
37
   local q = SILE.scratch.docbook[t]
×
38
   q[#q + 1] = val
×
39
end
40

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

465
   self:registerCommand("link", function (options, content)
×
466
      SILE.process(content)
×
467
      if options["xl:href"] then
×
468
         SILE.typesetter:typeset(" (")
×
469
         SILE.call("code", {}, { options["xl:href"] })
×
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

© 2025 Coveralls, Inc