• 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
/packages/simpletable/init.lua
1
local base = require("packages.base")
×
2

3
local package = pl.class(base)
×
4
package._name = "simpletable"
×
5

6
local tableTag, trTag, tdTag
7

8
function package:_init (options)
×
NEW
9
   base._init(self, options)
×
10

NEW
11
   if not SILE.scratch.simpletable then
×
NEW
12
      SILE.scratch.simpletable = { tables = {} }
×
13
   end
14

NEW
15
   if type(options) ~= "table" or pl.tablex.size(options) < 3 then
×
NEW
16
      options = {
×
17
         tableTag = "table",
18
         trTag = "tr",
19
         tdTag = "td",
20
      }
21
   end
22

NEW
23
   tableTag = SU.required(options, "tableTag", "setting up table class")
×
NEW
24
   trTag = SU.required(options, "trTag", "setting up table class")
×
NEW
25
   tdTag = SU.required(options, "tdTag", "setting up table class")
×
26

27
   -- This is a post init callback instead of the usual early command registration
28
   -- method using our package loader because we don't know what commands to register
29
   -- until we've been instantiated.
NEW
30
   self.class:registerPostinit(function (_)
×
NEW
31
      self:registerCommand(trTag, function (_, content)
×
NEW
32
         local tbl = SILE.scratch.simpletable.tables[#SILE.scratch.simpletable.tables]
×
NEW
33
         tbl[#tbl + 1] = {}
×
NEW
34
         SILE.process(content)
×
35
      end)
36

NEW
37
      self:registerCommand(tdTag, function (_, content)
×
NEW
38
         local tbl = SILE.scratch.simpletable.tables[#SILE.scratch.simpletable.tables]
×
NEW
39
         local row = tbl[#tbl]
×
NEW
40
         local hbox, hlist = SILE.typesetter:makeHbox(content)
×
NEW
41
         row[#row + 1] = {
×
42
            content = content,
43
            hbox = hbox,
44
         }
NEW
45
         if #hlist > 0 then
×
NEW
46
            SU.warn("Ignored migrating content in simpletable row (unsupported)")
×
47
         end
48
      end)
49

NEW
50
      self:registerCommand(tableTag, function (_, content)
×
NEW
51
         local tbl = {}
×
NEW
52
         table.insert(SILE.scratch.simpletable.tables, tbl)
×
NEW
53
         SILE.settings:temporarily(function ()
×
NEW
54
            SILE.settings:set("document.parindent", SILE.nodefactory.glue())
×
NEW
55
            SILE.process(content)
×
56
         end)
NEW
57
         SILE.typesetter:leaveHmode()
×
58
         -- Look down columns and find largest thing per column
NEW
59
         local colwidths = {}
×
NEW
60
         local col = 1
×
61
         local stuffInThisColumn
62
         repeat
NEW
63
            stuffInThisColumn = false
×
NEW
64
            for row = 1, #tbl do
×
NEW
65
               local cell = tbl[row][col]
×
NEW
66
               if cell then
×
NEW
67
                  stuffInThisColumn = true
×
NEW
68
                  if not colwidths[col] or cell.hbox.width > colwidths[col] then
×
NEW
69
                     colwidths[col] = cell.hbox.width
×
70
                  end
71
               end
72
            end
NEW
73
            col = col + 1
×
NEW
74
         until not stuffInThisColumn
×
75
         -- Now set each row at the given column width
NEW
76
         SILE.settings:temporarily(function ()
×
NEW
77
            SILE.settings:set("document.parindent", SILE.nodefactory.glue())
×
NEW
78
            for row = 1, #tbl do
×
NEW
79
               for colno = 1, #tbl[row] do
×
NEW
80
                  local hbox = tbl[row][colno].hbox
×
NEW
81
                  hbox.width = colwidths[colno]
×
NEW
82
                  SILE.typesetter:pushHbox(hbox)
×
83
               end
NEW
84
               SILE.typesetter:leaveHmode()
×
NEW
85
               SILE.call("smallskip")
×
86
            end
87
         end)
NEW
88
         SILE.typesetter:leaveHmode()
×
NEW
89
         table.remove(SILE.scratch.simpletable.tables)
×
90
      end)
91
   end)
92
end
93

94
package.documentation = [[
95
\begin{document}
96
This implements (badly) a very simple table formatting class.
97

98
It should be called as so:
99

100
\begin[type=autodoc:codeblock]{raw}
101
myclass:loadPackage("simpletable", {
102
 tableTag = "a",
103
 trTag = "b",
104
 tdTag = "c"
105
})
106
\end{raw}
107

108
This will define commands \code{\\a}, \code{\\b} and \code{\\c} which are equivalent to the \code{<table>, \code{<tr>} and \code{<td>} tags.
109

110
This is not a complete table implementation, and should be replaced by one which implements the css2.1 two-pass table formatting algorithm.
111
\end{document}
112
]]
×
113

114
return package
×
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