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

sile-typesetter / sile / 8288578143

14 Mar 2024 09:39PM UTC coverage: 64.155% (-10.6%) from 74.718%
8288578143

Pull #1904

github

alerque
chore(core): Fixup ec6ed657 which didn't shim old pack styles properly
Pull Request #1904: Merge develop into master (commit to next release being breaking)

1648 of 2421 new or added lines in 107 files covered. (68.07%)

1843 existing lines in 77 files now uncovered.

10515 of 16390 relevant lines covered (64.15%)

3306.56 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 SILE.scratch.docbook[t] = {} end
×
35
  local q = SILE.scratch.docbook[t]
×
36
  q[#q+1] = val
×
37
end
38

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

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

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

53
class.registerCommands = function (self)
54

55
  plain.registerCommands(self)
×
56

57
  -- Unfinished! commands found in howto.xml example document on docbook.org
58
  self:registerCommand("acronym", function (_, content) SILE.process(content) end)
×
59
  self:registerCommand("alt", function (_, content) SILE.process(content) end)
×
60
  self:registerCommand("note", function (_, content) SILE.process(content) end)
×
61
  self:registerCommand("colspec", function (_, content) SILE.process(content) end)
×
62
  self:registerCommand("phrase", function (_, content) SILE.process(content) end)
×
63
  self:registerCommand("literal", function (_, content) SILE.process(content) end)
×
64
  self:registerCommand("docbook-section-3-title", function (_, content) SILE.process(content) end)
×
65
  self:registerCommand("variablelist", function (_, content) SILE.process(content) end)
×
66
  self:registerCommand("varlistentry", function (_, content) SILE.process(content) end)
×
67
  self:registerCommand("term", function (_, content) SILE.process(content) end)
×
68
  self:registerCommand("procedure", function (_, content) SILE.process(content) end)
×
69
  self:registerCommand("step", function (_, content) SILE.process(content) end)
×
70
  self:registerCommand("screen", function (_, content) SILE.process(content) end)
×
71
  self:registerCommand("command", function (_, content) SILE.process(content) end)
×
72
  self:registerCommand("option", function (_, content) SILE.process(content) end)
×
73
  self:registerCommand("package", function (_, content) SILE.process(content) end)
×
74
  self:registerCommand("tip", function (_, content) SILE.process(content) end)
×
75
  self:registerCommand("varname", function (_, content) SILE.process(content) end)
×
76
  self:registerCommand("qandaset", function (_, content) SILE.process(content) end)
×
77
  self:registerCommand("qandadiv", function (_, content) SILE.process(content) end)
×
78
  self:registerCommand("qandaentry", function (_, content) SILE.process(content) end)
×
79
  self:registerCommand("question", function (_, content) SILE.process(content) end)
×
80
  self:registerCommand("answer", function (_, content) SILE.process(content) end)
×
81

82
  self:registerCommand("docbook-line", function (_, _)
×
83
    SILE.call("medskip")
×
84
    SILE.call("hrule", { height = "0.5pt", width = "50mm" })
×
85
    SILE.call("medskip")
×
86
  end)
87

88
  self:registerCommand("docbook-sectionsfont", function (_, content)
×
89
    SILE.call("font", { family = "DejaVu Sans", style = "Condensed", weight = 800 }, content)
×
90
  end)
91

92
  self:registerCommand("docbook-ttfont", function (_, content)
×
93
    SILE.call("font", { family = "Hack", size = "2ex" }, content)
×
94
  end)
95

96
  self:registerCommand("docbook-article-title", function (_, content)
×
97
    SILE.call("center", {}, function ()
×
98
      SILE.call("docbook-sectionsfont", {}, function ()
×
99
        SILE.call("font", { size = "20pt" }, content)
×
100
      end)
101
    end)
102
    SILE.call("bigskip")
×
103
  end)
104

105
  self:registerCommand("docbook-section-title", function (_, content)
×
106
    SILE.call("noindent")
×
107
    SILE.call("bigskip")
×
108
    SILE.call("docbook-sectionsfont", {}, {content})
×
109
    SILE.call("bigskip")
×
110
  end)
111

112
  self:registerCommand("docbook-main-author", function (_, content)
×
113
    SILE.call("center", {}, function()
×
114
      SILE.call("docbook-sectionsfont", {}, content)
×
115
    end)
116
    SILE.call("bigskip")
×
117
  end)
118

119

120
  self:registerCommand("docbook-section-1-title", function (_, content)
×
121
    SILE.call("font", { size = "16pt" }, function()
×
122
      SILE.call("docbook-section-title", {}, content)
×
123
    end)
124
  end)
125

126
  self:registerCommand("docbook-section-2-title", function (_, content)
×
127
    SILE.call("font", { size = "12pt" }, function()
×
128
      SILE.call("docbook-section-title", {}, content)
×
129
    end)
130
  end)
131

132
  self:registerCommand("docbook-titling", function (_, content)
×
133
    SILE.call("noindent")
×
134
    SILE.call("docbook-sectionsfont", {}, content)
×
135
  end)
136

137

138
  self:registerCommand("para", function (_, content)
×
139
    SILE.process(content)
×
140
    SILE.call("par")
×
141
  end)
142

143
  self:registerCommand("emphasis", function (_, content)
×
144
    SILE.call("em", {}, content)
×
145
  end)
146

147
  self:registerCommand("replaceable", function (_, content)
×
148
    SILE.call("em", {}, content)
×
149
  end)
150

151
  self:registerCommand("abbrev", function (_, content)
×
152
    SILE.call("font", { variant = "smallcaps" }, content)
×
153
  end)
154

155
  self:registerCommand("title", function (_, content)
×
156
    SILE.call("em", {}, content)
×
157
  end)
158

159
  self:registerCommand("personname", function (_, content)
×
160
    SILE.process(content)
×
161
  end)
162

163
  self:registerCommand("email", function (_, content)
×
164
    SILE.process(content)
×
165
  end)
166

167
  self:registerCommand("uri", function (_, content)
×
168
    SILE.call("code", {}, content)
×
169
  end)
170

171
  self:registerCommand("personblurb", function (_, content)
×
172
    SILE.call("font", { size = "2ex" }, content)
×
173
  end)
174

175
  self:registerCommand("affiliation", function (_, content)
×
176
    SILE.process(content)
×
177
  end)
178

179
  self:registerCommand("jobtitle", function (_, content)
×
180
    SILE.process(content)
×
181
  end)
182

183
  self:registerCommand("orgname", function (_, content)
×
184
    SILE.process(content)
×
185
  end)
186

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

191
  self:registerCommand("menuchoice", function (_, content)
×
192
    SILE.typesetter:typeset("“")
×
193
    SILE.process(content)
×
194
    SILE.typesetter:typeset("”")
×
195
  end)
196

197
  self:registerCommand("programlisting", function (_, content)
×
198
    SILE.call("verbatim", {}, content)
×
199
  end)
200

201
  self:registerCommand("tag", function (_, content)
×
202
    SILE.call("docbook-ttfont", {}, function ()
×
203
      SILE.typesetter:typeset("<")
×
204
      SILE.process(content)
×
205
      SILE.typesetter:typeset(">")
×
206
    end)
207
  end)
208

209
  self:registerCommand("code", function (_, content)
×
210
    SILE.call("docbook-ttfont", {}, content)
×
211
  end)
212

213
  self:registerCommand("filename", function (_, content)
×
214
    SILE.call("docbook-ttfont", {}, content)
×
215
  end)
216

217
  self:registerCommand("guimenu", function (_, content)
×
218
    SILE.call("docbook-ttfont", {}, content)
×
219
  end)
220

221
  self:registerCommand("guimenuitem", function (_, content)
×
222
    SILE.typesetter:typeset(" > ")
×
223
    SILE.call("docbook-ttfont", {}, content)
×
224
  end)
225

226
  self:registerCommand("guilabel", function (_, content)
×
227
    SILE.call("docbook-ttfont", {}, content)
×
228
  end)
229

230
  self:registerCommand("guibutton", function (_, content)
×
231
    SILE.call("docbook-ttfont", {}, content)
×
232
  end)
233

234
  self:registerCommand("computeroutput", function (_, content)
×
235
    SILE.call("docbook-ttfont", {}, content)
×
236
  end)
237

238
  self:registerCommand("xref", function (_, _)
×
239
    SILE.typesetter:typeset("XXX")
×
240
  end)
241

242
  self:registerCommand("citetitle", function (_, content)
×
243
    SILE.call("em", {}, content)
×
244
  end)
245

246
  self:registerCommand("quote", function (_, content)
×
247
    SILE.typesetter:typeset("“")
×
248
    SILE.process(content)
×
249
    SILE.typesetter:typeset("”")
×
250
  end)
251

252
  self:registerCommand("citation", function (_, content)
×
253
    SILE.typesetter:typeset("[")
×
254
    SILE.process(content)
×
255
    SILE.typesetter:typeset("]")
×
256
  end)
257

258
  self:registerCommand("thead", function (_, content)
×
259
    SILE.call("font", { weight = 800 }, content)
×
260
  end)
261

262
  self:registerCommand("tbody", function (_, content)
×
263
    SILE.process(content)
×
264
  end)
265

266
  self:registerCommand("mediaobject", function (_, content)
×
267
    SILE.process(content)
×
268
  end)
269

270
  self:registerCommand("imageobject", function (_, content)
×
271
    SILE.process(content)
×
272
  end)
273

274
  self:registerCommand("bibliography", function (_, content)
×
275
    SILE.call("font", { size = "16pt" }, function ()
×
276
      SILE.call("docbook-section-title", { "Bibliography" })
×
277
    end)
278
    SILE.call("par")
×
279
    SILE.call("font", { size = "2ex" }, content)
×
280
  end)
281

282
  self:registerCommand("bibliomixed", function (_, content)
×
283
    SILE.process(content)
×
284
    SILE.call("smallskip")
×
285
  end)
286

287
  self:registerCommand("bibliomisc", function (_, content)
×
288
    SILE.process(content)
×
289
  end)
290

291
  self:registerCommand("article", function (_, content)
×
292
    local info = SILE.inputter:findInTree(content, "info") or SILE.inputter:findInTree(content, "articleinfo")
×
293
    local title = SILE.inputter:findInTree(content, "title") or (info and SILE.inputter:findInTree(info, "title"))
×
294
    local author = SILE.inputter:findInTree(content, "author") or (info and SILE.inputter:findInTree(info, "author"))
×
295

296
    if title then
×
297
      SILE.call("docbook-article-title", {}, title)
×
298
      self.wipe(title)
×
299
    end
300
    if author then
×
301
      SILE.call("docbook-main-author", {}, function ()
×
302
        for _, t in ipairs(author) do
×
303
          if type(t) == "table" then
×
304
            SILE.call(t.command, {}, t)
×
305
            SILE.typesetter:leaveHmode()
×
306
            SILE.call("bigskip")
×
307
          end
308
        end
309
      end)
310
    end
311
    SILE.process(content)
×
312
    SILE.typesetter:chuck()
×
313
  end)
314

315
  self:registerCommand("info", function ()end)
×
316

317
  self:registerCommand("section", function (_, content)
×
318
    SILE.scratch.docbook.seclevel = SILE.scratch.docbook.seclevel + 1
×
319
    SILE.scratch.docbook.seccount[SILE.scratch.docbook.seclevel] = (SILE.scratch.docbook.seccount[SILE.scratch.docbook.seclevel] or 0) + 1
×
320
    while #(SILE.scratch.docbook.seccount) > SILE.scratch.docbook.seclevel do
×
321
      SILE.scratch.docbook.seccount[#(SILE.scratch.docbook.seccount)] = nil
×
322
    end
323
    local title = SILE.inputter:findInTree(content, "title")
×
324
    local number = table.concat(SILE.scratch.docbook.seccount, '.')
×
325
    if title then
×
326
      SILE.call("docbook-section-"..SILE.scratch.docbook.seclevel.."-title", {}, function ()
×
327
        SILE.typesetter:typeset(number.." ")
×
328
        SILE.process(title)
×
329
      end)
330
      self.wipe(title)
×
331
    end
332
    SILE.process(content)
×
333
    SILE.scratch.docbook.seclevel = SILE.scratch.docbook.seclevel - 1
×
334
  end)
335

336
  local function countedThing(thing, _, content)
337
    SILE.call("increment-counter", {id=thing})
×
338
    SILE.call("bigskip")
×
339
    SILE.call("docbook-line")
×
340
    SILE.call("docbook-titling", {}, function ()
×
341
      SILE.typesetter:typeset(thing.." ".. self.packages.counters:formatCounter(SILE.scratch.counters[thing]))
×
342
      local t = SILE.inputter:findInTree(content, "title")
×
343
      if t then
×
344
        SILE.typesetter:typeset(": ")
×
345
        SILE.process(t)
×
346
        self.wipe(t)
×
347
      end
348
    end)
349
    SILE.call("smallskip")
×
350
    SILE.process(content)
×
351
    SILE.call("docbook-line")
×
352
    SILE.call("bigskip")
×
353
  end
354

355
  self:registerCommand("example", function (options, content)
×
356
    countedThing("Example", options, content)
×
357
  end)
358

359
  self:registerCommand("table", function (options, content)
×
360
    countedThing("Table", options, content)
×
361
  end)
362
  self:registerCommand("figure", function (options, content)
×
363
    countedThing("Figure", options, content)
×
364
  end)
365

366
  local function docmook_measurement (value)
367
    SU.dump(value)
×
368
    value = value:gsub("(%d)$", "%1px") -- bare numbers are pixels, not points
×
369
    value = value:gsub("(%%)$", "%1lw") -- percentages are relative to viewport
×
370
    return SU.cast("measurement", value)
×
371
  end
372

373
  self:registerCommand("imagedata", function (options, _)
×
374
    local width = options.width and docmook_measurement(options.width)
×
375
    SILE.call("img", { src = options.fileref, width = width })
×
376
  end)
377

378
  self:registerCommand("itemizedlist", function (_, content)
×
379
    self.push("list", {type = "itemized"})
×
380
    SILE.call("medskip")
×
381
    -- Indentation
382
    SILE.process(content)
×
383
    SILE.call("medskip")
×
384
    self.pop("list")
×
385
  end)
386

387

388
  self:registerCommand("orderedlist", function (_, content)
×
389
    self.push("list", {type = "ordered", ctr = 1})
×
390
    SILE.call("medskip")
×
391
    -- Indentation
392
    SILE.process(content)
×
393
    SILE.call("medskip")
×
394
    self.pop("list")
×
395
  end)
396

397
  self:registerCommand("listitem", function (_, content)
×
398
    local ctx = self.val("list")
×
399
    if ctx and ctx.type == "ordered" then
×
400
      SILE.typesetter:typeset( ctx.ctr ..". ")
×
401
      ctx.ctr = ctx.ctr + 1
×
402
    elseif ctx and ctx.type == "itemized" then
×
403
      SILE.typesetter:typeset( "• ")
×
404
    -- elseif ctx and ctx.type == "" then
405
    --   -- Other types?
406
    else
407
      return SU.warn("Listitem in outer space")
×
408
    end
409
    SILE.call("noindent")
×
410
    for _=1, #ctx-1 do SILE.call("qquad") end -- Setting lskip better?
×
411
    SILE.process(content)
×
412
    SILE.call("medskip")
×
413
  end)
414

415
  self:registerCommand("link", function (options, content)
×
416
    SILE.process(content)
×
417
    if (options["xl:href"]) then
×
418
      SILE.typesetter:typeset(" (")
×
419
      SILE.call("code", {}, {options["xl:href"]})
×
420
      SILE.typesetter:typeset(")")
×
421
    end
422
  end)
423

424
end
425

426
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