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

sile-typesetter / sile / 14727381542

29 Apr 2025 06:54AM UTC coverage: 32.062% (+0.3%) from 31.768%
14727381542

push

github

alerque
chore(shapers): Remove workarounds for HB versions we haven't supported in ages

6464 of 20161 relevant lines covered (32.06%)

2446.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
696✔
3
      return
×
4
   end
5
   if SU.debugging("ast") then
1,392✔
6
      SU.debugAST(ast, 0)
×
7
   end
8
   if type(ast) == "function" then
696✔
9
      return ast()
156✔
10
   end
11
   for _, content in ipairs(ast) do
2,894✔
12
      if type(content) == "string" then
2,354✔
13
         SILE.typesetter:typeset(content)
2,650✔
14
      elseif type(content) == "function" then
1,029✔
15
         content()
×
16
      elseif SILE.Commands[content.command] then
1,029✔
17
         SILE.call(content.command, content.options, content)
2,056✔
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" }
195✔
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
97✔
35
      for _, format in ipairs(preloadedinputters) do
388✔
36
         local _ = SILE.inputters[format]
291✔
37
      end
38
   end
39
   local contentDetectionOrder = {}
97✔
40
   for _, inputter in pairs(SILE.inputters) do
388✔
41
      if inputter.order then
291✔
42
         table.insert(contentDetectionOrder, inputter)
291✔
43
      end
44
   end
45
   table.sort(contentDetectionOrder, function (a, b)
194✔
46
      return a.order < b.order
247✔
47
   end)
48
   local initialround = filename and 1 or 2
97✔
49
   for round = initialround, 3 do
100✔
50
      for _, inputter in ipairs(contentDetectionOrder) do
199✔
51
         SU.debug("inputter", "Running content type detection round", round, "with", inputter._name)
196✔
52
         if inputter.appropriate(round, filename, doc) then
392✔
53
            return inputter._name
97✔
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
129✔
63
      cpf = SILE.currentlyProcessingFile
32✔
64
      local caller = debug.getinfo(2, "Sl")
32✔
65
      SILE.currentlyProcessingFile = caller.short_src .. ":" .. caller.currentline
32✔
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])
420✔
74
      and SILE.inputter
97✔
75
   then
76
      inputter = SILE.inputter
×
77
   else
78
      format = format or detectFormat(doc, filename)
226✔
79
      if not SILE.quiet then
129✔
80
         io.stderr:write(("<%s> as %s\n"):format(SILE.currentlyProcessingFile, format))
129✔
81
      end
82
      inputter = SILE.inputters[format](options)
258✔
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
323✔
86
         SILE.inputter = inputter
97✔
87
      end
88
   end
89
   local pId = SILE.traceStack:pushDocument(SILE.currentlyProcessingFile, doc)
129✔
90
   inputter:process(doc)
129✔
91
   SILE.traceStack:pop(pId)
129✔
92
   if cpf then
129✔
93
      SILE.currentlyProcessingFile = cpf
32✔
94
   end
95
end
96

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

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