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

sile-typesetter / sile / 14284237390

05 Apr 2025 05:33PM UTC coverage: 63.158% (+31.8%) from 31.375%
14284237390

push

github

web-flow
Merge pull request #2248 from alerque/class-warfare

Normalize module layout across all module types

257 of 350 new or added lines in 14 files covered. (73.43%)

71 existing lines in 11 files now uncovered.

13670 of 21644 relevant lines covered (63.16%)

3070.68 hits per line

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

86.81
/core/process.lua
1
local function process (ast)
2
   if not ast then
843✔
3
      return
4✔
4
   end
5
   if SU.debugging("ast") then
1,678✔
NEW
6
      SU.debugAST(ast, 0)
×
7
   end
8
   if type(ast) == "function" then
839✔
9
      return ast()
188✔
10
   end
11
   for _, content in ipairs(ast) do
3,432✔
12
      if type(content) == "string" then
2,781✔
13
         SILE.typesetter:typeset(content)
3,120✔
14
      elseif type(content) == "function" then
1,221✔
15
         content()
2✔
16
      elseif SILE.Commands[content.command] then
1,220✔
17
         SILE.call(content.command, content.options, content)
2,428✔
18
      elseif not content.command and not content.id then
6✔
19
         local pId = SILE.traceStack:pushContent(content, "content")
6✔
20
         SILE.process(content)
6✔
21
         SILE.traceStack:pop(pId)
12✔
NEW
22
      elseif type(content) ~= "nil" then
×
NEW
23
         local pId = SILE.traceStack:pushContent(content)
×
NEW
24
         SU.error("Unknown command " .. (tostring(content.command or content.id)))
×
NEW
25
         SILE.traceStack:pop(pId)
×
26
      end
27
   end
28
end
29

30
local preloadedinputters = { "xml", "lua", "sil" }
223✔
31

32
local function detectFormat (doc, filename)
33
   -- Preload default reader types so content detection has something to work with
34
   if #SILE.inputters == 0 then
114✔
35
      for _, format in ipairs(preloadedinputters) do
456✔
36
         local _ = SILE.inputters[format]
342✔
37
      end
38
   end
39
   local contentDetectionOrder = {}
114✔
40
   for _, inputter in pairs(SILE.inputters) do
456✔
41
      if inputter.order then
342✔
42
         table.insert(contentDetectionOrder, inputter)
342✔
43
      end
44
   end
45
   table.sort(contentDetectionOrder, function (a, b)
228✔
46
      return a.order < b.order
305✔
47
   end)
48
   local initialround = filename and 1 or 2
114✔
49
   for round = initialround, 3 do
117✔
50
      for _, inputter in ipairs(contentDetectionOrder) do
233✔
51
         SU.debug("inputter", "Running content type detection round", round, "with", inputter._name)
230✔
52
         if inputter.appropriate(round, filename, doc) then
460✔
53
            return inputter._name
114✔
54
         end
55
      end
56
   end
NEW
57
   SU.error(("Unable to pick inputter to process input from '%s'"):format(filename))
×
58
end
59

60
local function processString (doc, format, filename, options)
61
   local cpf
62
   if not filename then
147✔
63
      cpf = SILE.currentlyProcessingFile
33✔
64
      local caller = debug.getinfo(2, "Sl")
33✔
65
      SILE.currentlyProcessingFile = caller.short_src .. ":" .. caller.currentline
33✔
66
   end
67
   -- In the event we're processing the master file *and* the user gave us
68
   -- a specific inputter to use, use it at the exclusion of all content type
69
   -- detection
70
   local inputter
71
   if
72
      filename
73
      and pl.path.normcase(pl.path.normpath(filename)) == pl.path.normcase(SILE.input.filenames[1])
489✔
74
      and SILE.inputter
114✔
75
   then
NEW
76
      inputter = SILE.inputter
×
77
   else
78
      format = format or detectFormat(doc, filename)
261✔
79
      if not SILE.quiet then
147✔
80
         io.stderr:write(("<%s> as %s\n"):format(SILE.currentlyProcessingFile, format))
147✔
81
      end
82
      inputter = SILE.inputters[format](options)
294✔
83
      -- If we did content detection *and* this is the master file, save the
84
      -- inputter for posterity and postambles
85
      if filename and pl.path.normcase(filename) == pl.path.normcase(SILE.input.filenames[1]:gsub("^-$", "STDIN")) then
375✔
86
         SILE.inputter = inputter
114✔
87
      end
88
   end
89
   local pId = SILE.traceStack:pushDocument(SILE.currentlyProcessingFile, doc)
147✔
90
   inputter:process(doc)
147✔
91
   SILE.traceStack:pop(pId)
147✔
92
   if cpf then
147✔
93
      SILE.currentlyProcessingFile = cpf
33✔
94
   end
95
end
96

97
local function processFile (filename, format, options)
98
   local lfs = require("lfs")
114✔
99
   local doc
100
   if filename == "-" then
114✔
NEW
101
      filename = "STDIN"
×
NEW
102
      doc = io.stdin:read("*a")
×
103
   else
104
      -- Turn slashes around in the event we get passed a path from a Windows shell
105
      filename = filename:gsub("\\", "/")
114✔
106
      if not SILE.masterFilename then
114✔
107
         SILE.masterFilename = pl.path.splitext(pl.path.normpath(filename))
456✔
108
      end
109
      if SILE.input.filenames[1] and not SILE.masterDir then
114✔
110
         SILE.masterDir = pl.path.dirname(SILE.input.filenames[1])
228✔
111
      end
112
      if SILE.masterDir and SILE.masterDir:len() >= 1 then
228✔
113
         _G.extendSilePath(SILE.masterDir)
114✔
114
         _G.extendSilePathRocks(SILE.masterDir .. "/lua_modules")
114✔
115
      end
116
      filename = SILE.resolveFile(filename) or SU.error("Could not find file '" .. filename .. "'")
228✔
117
      local mode = lfs.attributes(filename).mode
114✔
118
      if mode ~= "file" and mode ~= "named pipe" then
114✔
NEW
119
         SU.error(filename .. " isn't a file or named pipe, it's a " .. mode .. "!")
×
120
      end
121
      if SILE.makeDeps then
114✔
122
         SILE.makeDeps:add(filename)
114✔
123
      end
124
      local file, err = io.open(filename)
114✔
125
      if not file then
114✔
NEW
126
         print("Could not open " .. filename .. ": " .. err)
×
NEW
127
         return
×
128
      end
129
      doc = file:read("*a")
114✔
130
   end
131
   local cpf = SILE.currentlyProcessingFile
114✔
132
   SILE.currentlyProcessingFile = filename
114✔
133
   local pId = SILE.traceStack:pushDocument(filename, doc)
114✔
134
   local ret = SILE.processString(doc, format, filename, options)
114✔
135
   SILE.traceStack:pop(pId)
114✔
136
   SILE.currentlyProcessingFile = cpf
114✔
137
   return ret
114✔
138
end
139

140
return {
223✔
141
   process = process,
223✔
142
   processString = processString,
223✔
143
   processFile = processFile,
223✔
144
}
223✔
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