• 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

89.29
/inputters/xml.lua
1
local base = require("inputters.base")
92✔
2
local lxp = require("lxp")
92✔
3

4
local inputter = pl.class(base)
92✔
5
inputter._name = "xml"
92✔
6

7
inputter.order = 2
92✔
8

9
local function startcommand (parser, command, options)
10
  local stack = parser:getcallbacks().stack
710✔
11
  local lno, col, pos = parser:pos()
710✔
12
  local position = { lno = lno, col = col, pos = pos }
710✔
13
  -- create an empty command which content will be filled on closing tag
14
  local element = SU.ast.createCommand(command, options, nil, position)
710✔
15
  table.insert(stack, element)
710✔
16
end
17

18
local function endcommand (parser, command)
19
  local stack = parser:getcallbacks().stack
710✔
20
  local element = table.remove(stack)
710✔
21
  assert(element.command == command)
710✔
22
  local level = #stack
710✔
23
  table.insert(stack[level], element)
710✔
24
end
25

26
local function text (parser, msg)
27
  local stack = parser:getcallbacks().stack
1,069✔
28
  local element = stack[#stack]
1,069✔
29
  local n = #element
1,069✔
30
  if type(element[n]) == "string" then
1,069✔
31
    element[n] = element[n] .. msg
×
32
  else
33
    table.insert(element, msg)
1,069✔
34
  end
35
end
36

37
local function parse (doc)
38
  local content = {
16✔
39
    StartElement = startcommand,
16✔
40
    EndElement = endcommand,
16✔
41
    CharacterData = text,
16✔
42
    _nonstrict = true,
43
    stack = {{}}
16✔
44
  }
45
  local parser = lxp.new(content)
16✔
46
  local status, err
47
  if type(doc) == "string" then
16✔
48
    status, err = parser:parse(doc)
16✔
49
    if not status then return nil, err end
16✔
50
  else
51
    for element in pairs(doc) do
×
52
      status, err = parser:parse(element)
×
53
      if not status then return nil, err end
×
54
    end
55
  end
56
  status, err = parser:parse()
16✔
57
  if not status then return nil, err end
16✔
58
  parser:close()
16✔
59
  return content.stack[1][1]
16✔
60
end
61

62
function inputter.appropriate (round, filename, doc)
92✔
63
  if round == 1 then
96✔
64
    return filename:match(".xml$")
92✔
65
  elseif round == 2 then
4✔
66
    local sniff = doc:sub(1, 100):gsub("begin.*", "") or ""
6✔
67
    local promising = sniff:match("<")
3✔
68
    return promising and inputter.appropriate(3, filename, doc)
4✔
69
  elseif round == 3 then
1✔
70
    local _, err = parse(doc)
1✔
71
    return not err
1✔
72
  end
73
end
74

75
function inputter.parse (_, doc)
92✔
76
  local tree, err = parse(doc)
15✔
77
  if not tree then
15✔
78
    SU.error(err)
×
79
  end
80
  -- XML documents can have any root element, and it should be up to the class
81
  -- to supply handling far whatever that element that is in a specific format.
82
  -- Hence we wrap the actual DOM in an extra element of our own if and only if
83
  -- it doesn't look like a native SILE one already.
84
  local rootelement = tree.command
15✔
85
  if rootelement ~= "sile" and rootelement ~= "document" then
15✔
NEW
86
    tree = SU.ast.createCommand("document", {}, tree)
×
87
  end
88
  return { tree }
15✔
89
end
90

91
return inputter
92✔
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