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

sile-typesetter / sile / 14384044172

10 Apr 2025 03:07PM UTC coverage: 40.142% (+10.8%) from 29.317%
14384044172

push

github

alerque
Merge branch 'cairo-is-still-in-egypt'

3 of 51 new or added lines in 3 files covered. (5.88%)

302 existing lines in 20 files now uncovered.

6876 of 17129 relevant lines covered (40.14%)

2601.39 hits per line

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

84.62
/core/process.lua
1
local function process (ast)
2
   if not ast then
465✔
UNCOV
3
      return
×
4
   end
5
   if SU.debugging("ast") then
930✔
6
      SU.debugAST(ast, 0)
×
7
   end
8
   if type(ast) == "function" then
465✔
9
      return ast()
79✔
10
   end
11
   for _, content in ipairs(ast) do
2,343✔
12
      if type(content) == "string" then
1,957✔
13
         SILE.typesetter:typeset(content)
2,224✔
14
      elseif type(content) == "function" then
845✔
UNCOV
15
         content()
×
16
      elseif SILE.Commands[content.command] then
845✔
17
         SILE.call(content.command, content.options, content)
1,688✔
18
      elseif not content.command and not content.id then
1✔
19
         local pId = SILE.traceStack:pushContent(content, "content")
1✔
20
         SILE.process(content)
1✔
21
         SILE.traceStack:pop(pId)
2✔
22
      elseif type(content) ~= "nil" then
×
23
         local pId = SILE.traceStack:pushContent(content)
×
24
         SU.error("Unknown command " .. (tostring(content.command or content.id)))
×
25
         SILE.traceStack:pop(pId)
×
26
      end
27
   end
28
end
29

30
local preloadedinputters = { "xml", "lua", "sil" }
149✔
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
76✔
35
      for _, format in ipairs(preloadedinputters) do
304✔
36
         local _ = SILE.inputters[format]
228✔
37
      end
38
   end
39
   local contentDetectionOrder = {}
76✔
40
   for _, inputter in pairs(SILE.inputters) do
304✔
41
      if inputter.order then
228✔
42
         table.insert(contentDetectionOrder, inputter)
228✔
43
      end
44
   end
45
   table.sort(contentDetectionOrder, function (a, b)
152✔
46
      return a.order < b.order
203✔
47
   end)
48
   local initialround = filename and 1 or 2
76✔
49
   for round = initialround, 3 do
76✔
50
      for _, inputter in ipairs(contentDetectionOrder) do
145✔
51
         SU.debug("inputter", "Running content type detection round", round, "with", inputter._name)
145✔
52
         if inputter.appropriate(round, filename, doc) then
290✔
53
            return inputter._name
76✔
54
         end
55
      end
56
   end
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
101✔
63
      cpf = SILE.currentlyProcessingFile
25✔
64
      local caller = debug.getinfo(2, "Sl")
25✔
65
      SILE.currentlyProcessingFile = caller.short_src .. ":" .. caller.currentline
25✔
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])
329✔
74
      and SILE.inputter
76✔
75
   then
76
      inputter = SILE.inputter
×
77
   else
78
      format = format or detectFormat(doc, filename)
177✔
79
      if not SILE.quiet then
101✔
80
         io.stderr:write(("<%s> as %s\n"):format(SILE.currentlyProcessingFile, format))
101✔
81
      end
82
      inputter = SILE.inputters[format](options)
202✔
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
253✔
86
         SILE.inputter = inputter
76✔
87
      end
88
   end
89
   local pId = SILE.traceStack:pushDocument(SILE.currentlyProcessingFile, doc)
101✔
90
   inputter:process(doc)
101✔
91
   SILE.traceStack:pop(pId)
101✔
92
   if cpf then
101✔
93
      SILE.currentlyProcessingFile = cpf
25✔
94
   end
95
end
96

97
local function processFile (filename, format, options)
98
   local lfs = require("lfs")
76✔
99
   local doc
100
   if filename == "-" then
76✔
101
      filename = "STDIN"
×
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("\\", "/")
76✔
106
      if not SILE.masterFilename then
76✔
107
         SILE.masterFilename = pl.path.splitext(pl.path.normpath(filename))
304✔
108
      end
109
      if SILE.input.filenames[1] and not SILE.masterDir then
76✔
110
         SILE.masterDir = pl.path.dirname(SILE.input.filenames[1])
152✔
111
      end
112
      if SILE.masterDir and SILE.masterDir:len() >= 1 then
152✔
113
         _G.extendSilePath(SILE.masterDir)
76✔
114
         _G.extendSilePathRocks(SILE.masterDir .. "/lua_modules")
76✔
115
      end
116
      filename = SILE.resolveFile(filename) or SU.error("Could not find file '" .. filename .. "'")
152✔
117
      local mode = lfs.attributes(filename).mode
76✔
118
      if mode ~= "file" and mode ~= "named pipe" then
76✔
119
         SU.error(filename .. " isn't a file or named pipe, it's a " .. mode .. "!")
×
120
      end
121
      if SILE.makeDeps then
76✔
122
         SILE.makeDeps:add(filename)
76✔
123
      end
124
      local file, err = io.open(filename)
76✔
125
      if not file then
76✔
126
         print("Could not open " .. filename .. ": " .. err)
×
127
         return
×
128
      end
129
      doc = file:read("*a")
76✔
130
   end
131
   local cpf = SILE.currentlyProcessingFile
76✔
132
   SILE.currentlyProcessingFile = filename
76✔
133
   local pId = SILE.traceStack:pushDocument(filename, doc)
76✔
134
   local ret = SILE.processString(doc, format, filename, options)
76✔
135
   SILE.traceStack:pop(pId)
76✔
136
   SILE.currentlyProcessingFile = cpf
76✔
137
   return ret
76✔
138
end
139

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