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

sile-typesetter / sile / 11534409649

26 Oct 2024 07:27PM UTC coverage: 33.196% (-28.7%) from 61.897%
11534409649

push

github

alerque
chore(tooling): Update editor-config key for stylua as accepted upstream

Our setting addition is still not in a tagged release, but the PR was
accepted into the default branch of stylua. This means you no longer
need to run my fork of Stylua to get this project's style, you just nead
any build from the main development branch. However the config key was
renamed as part of the acceptance, so this is the relevant adjustment.

5810 of 17502 relevant lines covered (33.2%)

1300.57 hits per line

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

63.53
/classes/book.lua
1
--- book document class.
2
-- @use classes.book
3

4
local plain = require("classes.plain")
33✔
5

6
local class = pl.class(plain)
33✔
7
class._name = "book"
33✔
8

9
class.defaultFrameset = {
33✔
10
   content = {
33✔
11
      left = "8.3%pw",
12
      right = "86%pw",
13
      top = "11.6%ph",
14
      bottom = "top(footnotes)",
15
   },
33✔
16
   folio = {
33✔
17
      left = "left(content)",
18
      right = "right(content)",
19
      top = "bottom(footnotes)+3%ph",
20
      bottom = "bottom(footnotes)+5%ph",
21
   },
33✔
22
   runningHead = {
33✔
23
      left = "left(content)",
24
      right = "right(content)",
25
      top = "top(content)-8%ph",
26
      bottom = "top(content)-3%ph",
27
   },
33✔
28
   footnotes = {
33✔
29
      left = "left(content)",
30
      right = "right(content)",
31
      height = "0",
32
      bottom = "83.3%ph",
33
   },
33✔
34
}
33✔
35

36
function class:_init (options)
33✔
37
   plain._init(self, options)
33✔
38
   self:loadPackage("counters")
33✔
39
   self:loadPackage("masters", {
66✔
40
      {
41
         id = "right",
42
         firstContentFrame = self.firstContentFrame,
33✔
43
         frames = self.defaultFrameset,
33✔
44
      },
33✔
45
   })
46
   self:loadPackage("twoside", {
33✔
47
      oddPageMaster = "right",
48
      evenPageMaster = "left",
49
   })
50
   self:loadPackage("tableofcontents")
33✔
51
   self:loadPackage("footnotes", {
66✔
52
      insertInto = "footnotes",
53
      stealFrom = { "content" },
33✔
54
   })
55
   if not SILE.scratch.headers then
33✔
56
      SILE.scratch.headers = {}
33✔
57
   end
58
end
59

60
function class:endPage ()
33✔
61
   if not SILE.scratch.headers.skipthispage then
69✔
62
      if self:oddPage() and SILE.scratch.headers.right then
132✔
63
         SILE.typesetNaturally(SILE.getFrame("runningHead"), function ()
4✔
64
            SILE.settings:toplevelState()
2✔
65
            SILE.settings:set("current.parindent", SILE.types.node.glue())
4✔
66
            SILE.settings:set("document.lskip", SILE.types.node.glue())
4✔
67
            SILE.settings:set("document.rskip", SILE.types.node.glue())
4✔
68
            -- SILE.settings:set("typesetter.parfillskip", SILE.types.node.glue())
69
            SILE.process(SILE.scratch.headers.right)
2✔
70
            SILE.call("par")
2✔
71
         end)
72
      elseif not self:oddPage() and SILE.scratch.headers.left then
128✔
73
         SILE.typesetNaturally(SILE.getFrame("runningHead"), function ()
×
74
            SILE.settings:toplevelState()
×
75
            SILE.settings:set("current.parindent", SILE.types.node.glue())
×
76
            SILE.settings:set("document.lskip", SILE.types.node.glue())
×
77
            SILE.settings:set("document.rskip", SILE.types.node.glue())
×
78
            -- SILE.settings:set("typesetter.parfillskip", SILE.types.node.glue())
79
            SILE.process(SILE.scratch.headers.left)
×
80
            SILE.call("par")
×
81
         end)
82
      end
83
   end
84
   SILE.scratch.headers.skipthispage = false
69✔
85
   return plain.endPage(self)
69✔
86
end
87

88
function class:finish ()
33✔
89
   local ret = plain.finish(self)
33✔
90
   return ret
33✔
91
end
92

93
function class:registerCommands ()
33✔
94
   plain.registerCommands(self)
33✔
95

96
   self:registerCommand("left-running-head", function (_, content)
66✔
97
      local closure = SILE.settings:wrap()
×
98
      SILE.scratch.headers.left = function ()
×
99
         closure(content)
×
100
      end
101
   end, "Text to appear on the top of the left page")
33✔
102

103
   self:registerCommand("right-running-head", function (_, content)
66✔
104
      local closure = SILE.settings:wrap()
3✔
105
      SILE.scratch.headers.right = function ()
3✔
106
         closure(content)
2✔
107
      end
108
   end, "Text to appear on the top of the right page")
36✔
109

110
   self:registerCommand("book:sectioning", function (options, content)
66✔
111
      local level = SU.required(options, "level", "book:sectioning")
2✔
112
      local number
113
      if SU.boolean(options.numbering, true) then
4✔
114
         SILE.call("increment-multilevel-counter", { id = "sectioning", level = level })
2✔
115
         number = self.packages.counters:formatMultilevelCounter(self:getMultilevelCounter("sectioning"))
6✔
116
      end
117
      if SU.boolean(options.toc, true) then
4✔
118
         SILE.call("tocentry", { level = level, number = number }, SU.ast.subContent(content))
4✔
119
      end
120
      if SU.boolean(options.numbering, true) then
4✔
121
         if options.msg then
2✔
122
            SILE.call("fluent", { number = number }, { options.msg })
×
123
         else
124
            SILE.call("show-multilevel-counter", { id = "sectioning" })
2✔
125
         end
126
      end
127
   end)
128

129
   self:registerCommand("book:chapter:post", function (_, _)
66✔
130
      SILE.call("par")
×
131
      SILE.call("noindent")
×
132
   end)
133

134
   self:registerCommand("book:section:post", function (_, _)
66✔
135
      SILE.process({ " " })
2✔
136
   end)
137

138
   self:registerCommand("book:subsection:post", function (_, _)
66✔
139
      SILE.process({ " " })
×
140
   end)
141

142
   self:registerCommand("book:left-running-head-font", function (_, content)
66✔
143
      SILE.call("font", { size = "9pt" }, content)
×
144
   end)
145

146
   self:registerCommand("book:right-running-head-font", function (_, content)
66✔
147
      SILE.call("font", { size = "9pt", style = "Italic" }, content)
1✔
148
   end)
149

150
   self:registerCommand("chapter", function (options, content)
66✔
151
      SILE.call("par")
×
152
      SILE.call("open-spread", { double = false })
×
153
      SILE.call("noindent")
×
154
      SILE.scratch.headers.right = nil
×
155
      SILE.call("set-counter", { id = "footnote", value = 1 })
×
156
      SILE.call("book:chapterfont", {}, function ()
×
157
         SILE.call("book:sectioning", {
×
158
            numbering = options.numbering,
159
            toc = options.toc,
160
            level = 1,
161
            msg = "book-chapter-title",
162
         }, content)
×
163
      end)
164
      local lang = SILE.settings:get("document.language")
×
165
      local postcmd = "book:chapter:post"
×
166
      if SILE.Commands[postcmd .. ":" .. lang] then
×
167
         postcmd = postcmd .. ":" .. lang
×
168
      end
169
      SILE.call("nofoliothispage")
×
170
      SILE.call(postcmd)
×
171
      SILE.call("book:chapterfont", {}, content)
×
172
      SILE.call("left-running-head", {}, function ()
×
173
         SILE.settings:temporarily(function ()
×
174
            SILE.call("book:left-running-head-font", {}, content)
×
175
         end)
176
      end)
177
      SILE.call("novbreak")
×
178
      SILE.call("par")
×
179
      SILE.call("novbreak")
×
180
      SILE.call("bigskip")
×
181
      SILE.call("novbreak")
×
182
      -- English typography (notably) expects the first paragraph under a section
183
      -- not to be indented. Frenchies, don't use this class :)
184
      SILE.call("noindent")
×
185
   end, "Begin a new chapter")
33✔
186

187
   self:registerCommand("section", function (options, content)
66✔
188
      SILE.call("par")
2✔
189
      SILE.call("noindent")
2✔
190
      SILE.call("bigskip")
2✔
191
      SILE.call("goodbreak")
2✔
192
      SILE.call("book:sectionfont", {}, function ()
4✔
193
         SILE.call("book:sectioning", {
4✔
194
            numbering = options.numbering,
2✔
195
            toc = options.toc,
2✔
196
            level = 2,
197
         }, content)
2✔
198
         local lang = SILE.settings:get("document.language")
2✔
199
         local postcmd = "book:section:post"
2✔
200
         if SILE.Commands[postcmd .. ":" .. lang] then
2✔
201
            postcmd = postcmd .. ":" .. lang
×
202
         end
203
         SILE.call(postcmd)
2✔
204
         SILE.process(content)
2✔
205
      end)
206
      if not SILE.scratch.counters.folio.off then
2✔
207
         SILE.call("right-running-head", {}, function ()
4✔
208
            SILE.call("book:right-running-head-font", {}, function ()
2✔
209
               SILE.call("raggedleft", {}, function ()
2✔
210
                  SILE.settings:temporarily(function ()
2✔
211
                     if SU.boolean(options.numbering, true) then
2✔
212
                        SILE.call("show-multilevel-counter", { id = "sectioning", level = 2 })
1✔
213
                        SILE.typesetter:typeset(" ")
1✔
214
                     end
215
                     SILE.process(content)
1✔
216
                  end)
217
               end)
218
            end)
219
         end)
220
      end
221
      SILE.call("par")
2✔
222
      SILE.call("novbreak")
2✔
223
      SILE.call("smallskip")
2✔
224
      SILE.call("novbreak")
2✔
225
      -- English typography (notably) expects the first paragraph under a section
226
      -- not to be indented. Frenchies, don't use this class :)
227
      SILE.call("noindent")
2✔
228
   end, "Begin a new section")
35✔
229

230
   self:registerCommand("subsection", function (options, content)
66✔
231
      SILE.call("par")
×
232
      SILE.call("noindent")
×
233
      SILE.call("medskip")
×
234
      SILE.call("goodbreak")
×
235
      SILE.call("book:subsectionfont", {}, function ()
×
236
         SILE.call("book:sectioning", {
×
237
            numbering = options.numbering,
238
            toc = options.toc,
239
            level = 3,
240
         }, content)
×
241
         local lang = SILE.settings:get("document.language")
×
242
         local postcmd = "book:subsection:post"
×
243
         if SILE.Commands[postcmd .. ":" .. lang] then
×
244
            postcmd = postcmd .. ":" .. lang
×
245
         end
246
         SILE.call(postcmd)
×
247
         SILE.process(content)
×
248
      end)
249
      SILE.call("par")
×
250
      SILE.call("novbreak")
×
251
      SILE.call("smallskip")
×
252
      SILE.call("novbreak")
×
253
      -- English typography (notably) expects the first paragraph under a section
254
      -- not to be indented. Frenchies, don't use this class :)
255
      SILE.call("noindent")
×
256
   end, "Begin a new subsection")
33✔
257

258
   self:registerCommand("book:chapterfont", function (_, content)
66✔
259
      SILE.settings:temporarily(function ()
×
260
         SILE.call("font", { weight = 800, size = "22pt" }, content)
×
261
      end)
262
   end)
263
   self:registerCommand("book:sectionfont", function (_, content)
66✔
264
      SILE.settings:temporarily(function ()
4✔
265
         SILE.call("font", { weight = 800, size = "15pt" }, content)
2✔
266
      end)
267
   end)
268

269
   self:registerCommand("book:subsectionfont", function (_, content)
66✔
270
      SILE.settings:temporarily(function ()
×
271
         SILE.call("font", { weight = 800, size = "12pt" }, content)
×
272
      end)
273
   end)
274
end
275

276
return class
33✔
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