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

sile-typesetter / sile / 14502192980

16 Apr 2025 08:26PM UTC coverage: 57.267% (-5.4%) from 62.627%
14502192980

push

github

alerque
chore(packages): Remove unused package interdependency, url doesn't need verbatim

Reported-by: Omikhleia <didier.willis@gmail.com>

12352 of 21569 relevant lines covered (57.27%)

871.56 hits per line

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

80.22
/core/process.lua
1
local function process (ast)
2
   if not ast then
134✔
3
      return
×
4
   end
5
   if SU.debugging("ast") then
268✔
6
      SU.debugAST(ast, 0)
×
7
   end
8
   if type(ast) == "function" then
134✔
9
      return ast()
19✔
10
   end
11
   for _, content in ipairs(ast) do
627✔
12
      if type(content) == "string" then
512✔
13
         SILE.typesetter:typeset(content)
580✔
14
      elseif type(content) == "function" then
222✔
15
         content()
×
16
      elseif SILE.Commands[content.command] then
222✔
17
         SILE.call(content.command, content.options, content)
444✔
18
      elseif not content.command and not content.id then
×
19
         local pId = SILE.traceStack:pushContent(content, "content")
×
20
         SILE.process(content)
×
21
         SILE.traceStack:pop(pId)
×
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" }
50✔
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
27✔
35
      for _, format in ipairs(preloadedinputters) do
108✔
36
         local _ = SILE.inputters[format]
81✔
37
      end
38
   end
39
   local contentDetectionOrder = {}
27✔
40
   for _, inputter in pairs(SILE.inputters) do
108✔
41
      if inputter.order then
81✔
42
         table.insert(contentDetectionOrder, inputter)
81✔
43
      end
44
   end
45
   table.sort(contentDetectionOrder, function (a, b)
54✔
46
      return a.order < b.order
69✔
47
   end)
48
   local initialround = filename and 1 or 2
27✔
49
   for round = initialround, 3 do
27✔
50
      for _, inputter in ipairs(contentDetectionOrder) do
52✔
51
         SU.debug("inputter", "Running content type detection round", round, "with", inputter._name)
52✔
52
         if inputter.appropriate(round, filename, doc) then
104✔
53
            return inputter._name
27✔
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
35✔
63
      cpf = SILE.currentlyProcessingFile
8✔
64
      local caller = debug.getinfo(2, "Sl")
8✔
65
      SILE.currentlyProcessingFile = caller.short_src .. ":" .. caller.currentline
8✔
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])
116✔
74
      and SILE.inputter
27✔
75
   then
76
      inputter = SILE.inputter
×
77
   else
78
      format = format or detectFormat(doc, filename)
62✔
79
      if not SILE.quiet then
35✔
80
         io.stderr:write(("<%s> as %s\n"):format(SILE.currentlyProcessingFile, format))
35✔
81
      end
82
      inputter = SILE.inputters[format](options)
70✔
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
89✔
86
         SILE.inputter = inputter
27✔
87
      end
88
   end
89
   local pId = SILE.traceStack:pushDocument(SILE.currentlyProcessingFile, doc)
35✔
90
   inputter:process(doc)
35✔
91
   SILE.traceStack:pop(pId)
35✔
92
   if cpf then
35✔
93
      SILE.currentlyProcessingFile = cpf
8✔
94
   end
95
end
96

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

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