• 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
/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)
×
9
   base._init(self, options)
×
10

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

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

23
   tableTag = SU.required(options, "tableTag", "setting up table class")
×
24
   trTag = SU.required(options, "trTag", "setting up table class")
×
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.
30
   self.class:registerPostinit(function (_)
×
31
      self:registerCommand(trTag, function (_, content)
×
32
         local tbl = SILE.scratch.simpletable.tables[#SILE.scratch.simpletable.tables]
×
33
         tbl[#tbl + 1] = {}
×
34
         SILE.process(content)
×
35
      end)
36

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

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