summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/luatex/luaxml/luaxml-selectors.lua
blob: 1e65d3b8058f8ba25b0ec5b722dc9318e3e8e525 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
--module(...,package.seeall)

local M =  {}
local inside = 0
local function makeTag(s)
   local function makeTag(fuf)
     return fuf .. "[^>]*"
   end
   local print = texio.write_nl
   if inside > 0 then print ("inside "..inside) else print("outside") end
   --[[if inside then
     return s .. "[^>]*"
   else
     inside = true--]]	   
     inside = inside + 1
     local f = "<"..s.."[^>]*>"
     inside = inside - 1
     return f
   --end
end

M.makeTag = makeTag
local function matchTag(tg)
   return makeTag(tg)
end
M.matchTag=matchTag
local function matchDescendand(a,b)
   return makeTag(a)..makeTag(b)
end
M.matchDescendand = matchDescendand

local function matchChild(a,b)
   return makeTag(a)..".*"..makeTag(b)
end
M.matchChild = matchChild

local function matchSibling(a,b)
   return a .. "[^>]*".."@%("..b.."[^>]*%)"
end
M.matchSibling = matchSibling

local function matchClass(tg,class)
   return tg.."[^>]*class=[|]*[^>]*|"..class.."[^>]*|"
end

M.matchClass = matchClass
local function matchId(tg,id)
   return tg.."[^>]*id="..id	
end
M.matchId = matchId
local matcher = {}
M.matcher= matcher
local function makeElement(s)
  local function makeTag(fuf)
    return fuf .. "[^>]*"
  end
  return "<"..s .. "[^>]*>"
end

M.makeElement = makeElement
function matcher.new()
  local self =  {}
  local selectors={}
  function self:addSelector(sel,val)
     selectors[sel.."$"] = val
  end
  function self:testPath(path,fn)
    for k, v in pairs(selectors) do
       if path:match(k) then
         fn(v)
       end
    end
  end
  return self
end
return M