summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/luatex
diff options
context:
space:
mode:
authorKarl Berry <karl@freefriends.org>2021-10-07 20:33:37 +0000
committerKarl Berry <karl@freefriends.org>2021-10-07 20:33:37 +0000
commite33d70fb04b016cc65621ba1907ecb4ddc8e650e (patch)
treecf2dd972aba6ac323a34e75a8d04308577ccb994 /Master/texmf-dist/tex/luatex
parentc764cdb0602ea9a4e41eea633127779c52b46290 (diff)
luaxml (7oct21)
git-svn-id: svn://tug.org/texlive/trunk@60709 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/tex/luatex')
-rw-r--r--Master/texmf-dist/tex/luatex/luaxml/luaxml-cssquery.lua22
-rw-r--r--Master/texmf-dist/tex/luatex/luaxml/luaxml-transform.lua9
2 files changed, 23 insertions, 8 deletions
diff --git a/Master/texmf-dist/tex/luatex/luaxml/luaxml-cssquery.lua b/Master/texmf-dist/tex/luatex/luaxml/luaxml-cssquery.lua
index 062d66d7456..14d1b66fdb4 100644
--- a/Master/texmf-dist/tex/luatex/luaxml/luaxml-cssquery.lua
+++ b/Master/texmf-dist/tex/luatex/luaxml/luaxml-cssquery.lua
@@ -41,11 +41,15 @@ local function cssquery()
local query = query or {}
local specificity = 0
for _, item in ipairs(query.query or {}) do
- for key, value in pairs(item) do
+ for _, t in ipairs(item) do
+ local key = t.key
+ -- for key, value in pairs(item) do
if key == "id" then
specificity = specificity + 100
elseif key == "tag" then
specificity = specificity + 1
+ elseif key == "any" then
+ -- * has 0 specificity
else
specificity = specificity + 10
end
@@ -215,7 +219,7 @@ local function cssquery()
-- ignore combinators in this function
else
if type(value) == "table" then value = table.concat(value, ":") end
- print("unsupported feature", key, value)
+ self:debug_print("unsupported feature", key, value)
return false
end
-- TODO: Add more cases
@@ -226,7 +230,9 @@ local function cssquery()
local function test_object(query, el)
-- test one object in CSS selector
local matched = {}
- for key, value in pairs(query) do
+ -- for key, value in pairs(query) do
+ for _, part in ipairs(query) do
+ local key, value = part.key, part.value
local test = test_part(key, value, el)
if test~= true then return false end
matched[#matched+1] = test
@@ -252,9 +258,10 @@ local function cssquery()
local selector = query[#query] -- get the last item in selector query
if not selector then return nil end
-- detect if this selector is a combinator"
- if selector and selector.combinator then
+ -- combinator object must have only one part, so we can assume that it is in the first part
+ if selector and selector[1].key == "combinator" then
-- save the combinator and select next selector from the query
- combinator = selector.combinator
+ combinator = selector[1].value
table.remove(query) -- remove combinator from query
end
return combinator
@@ -271,7 +278,7 @@ local function cssquery()
local function match_query(query, el)
local function match_parent(query, el)
- -- loop over the whole elemnt three and try to mach the css selector
+ -- loop over the whole element tree and try to mach the css selector
if el and el:is_element() then
local query = query or {}
local object = query[#query]
@@ -354,6 +361,7 @@ local function cssquery()
for _, part in ipairs(item) do
local t = {}
for _, atom in ipairs(part) do
+
local key = atom[1]
local value
if not atom[3] then
@@ -370,7 +378,7 @@ local function cssquery()
-- to match namespace:element
value=value:gsub("|", ":")
end
- t[key] = value
+ t[#t+1] = {key=key, value=value}
end
query[#query + 1] = t
end
diff --git a/Master/texmf-dist/tex/luatex/luaxml/luaxml-transform.lua b/Master/texmf-dist/tex/luatex/luaxml/luaxml-transform.lua
index 9ea4595ea71..d7631ac78e6 100644
--- a/Master/texmf-dist/tex/luatex/luaxml/luaxml-transform.lua
+++ b/Master/texmf-dist/tex/luatex/luaxml/luaxml-transform.lua
@@ -30,6 +30,13 @@ local function match_css(element,csspar)
local selectors = css:match_querylist(element)
if #selectors == 0 then return nil end
-- return function with the highest specificity
+ local last_specificity = selectors[1].specificity
+ -- if multiple selectors have the same specificity, return the last one
+ for i, x in ipairs(selectors) do
+ if x.specificity < last_specificity then
+ return selectors[i-1].func
+ end
+ end
return selectors[1].func
end
@@ -135,7 +142,7 @@ local function simple_content(s,parameters)
elseif name:match("^[0-9]+$") then
local child = get_child_element(element, tonumber(name))
if child then
- return process_children(child, parameters)
+ return process_tree(child)
end
-- @<CSS selector> returns contents of matched selectors
else