• 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
/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

32
    self:registerCommand(trTag, function(_, content)
×
33
      local tbl = SILE.scratch.simpletable.tables[#(SILE.scratch.simpletable.tables)]
×
34
      tbl[#tbl+1] = {}
×
35
      SILE.process(content)
×
36
    end)
37

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

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

93
  end)
94

95
end
96

97
package.documentation = [[
98
\begin{document}
99
This implements (badly) a very simple table formatting class.
100

101
It should be called as so:
102

103
\begin[type=autodoc:codeblock]{raw}
104
myclass:loadpackage("simpletable", {
105
 tabletag = "a",
106
 trtag = "b",
107
 tdtag = "c"
108
})
109
\end{raw}
110

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

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

117
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

© 2026 Coveralls, Inc