summaryrefslogtreecommitdiff
path: root/macros/luatex/generic/luaxml
diff options
context:
space:
mode:
Diffstat (limited to 'macros/luatex/generic/luaxml')
-rw-r--r--macros/luatex/generic/luaxml/README2
-rw-r--r--macros/luatex/generic/luaxml/luaxml-cssquery.lua22
-rw-r--r--macros/luatex/generic/luaxml/luaxml-transform.lua9
-rw-r--r--macros/luatex/generic/luaxml/luaxml.pdfbin118178 -> 118191 bytes
-rw-r--r--macros/luatex/generic/luaxml/luaxml.tex2
5 files changed, 25 insertions, 10 deletions
diff --git a/macros/luatex/generic/luaxml/README b/macros/luatex/generic/luaxml/README
index bea8ba60fc..38ba699686 100644
--- a/macros/luatex/generic/luaxml/README
+++ b/macros/luatex/generic/luaxml/README
@@ -28,7 +28,7 @@ Author
------
Michal Hoftich
Email: michal.h21@gmail.com
-Version: v0.1p, 2021-09-10
+Version: v0.1q, 2021-10-06
Original authors: Paul Chakravarti and Manoel Campos (http://manoelcampos.com)
diff --git a/macros/luatex/generic/luaxml/luaxml-cssquery.lua b/macros/luatex/generic/luaxml/luaxml-cssquery.lua
index 062d66d745..14d1b66fdb 100644
--- a/macros/luatex/generic/luaxml/luaxml-cssquery.lua
+++ b/macros/luatex/generic/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/macros/luatex/generic/luaxml/luaxml-transform.lua b/macros/luatex/generic/luaxml/luaxml-transform.lua
index 9ea4595ea7..d7631ac78e 100644
--- a/macros/luatex/generic/luaxml/luaxml-transform.lua
+++ b/macros/luatex/generic/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
diff --git a/macros/luatex/generic/luaxml/luaxml.pdf b/macros/luatex/generic/luaxml/luaxml.pdf
index 89f9c3d1ed..4f00cb6f69 100644
--- a/macros/luatex/generic/luaxml/luaxml.pdf
+++ b/macros/luatex/generic/luaxml/luaxml.pdf
Binary files differ
diff --git a/macros/luatex/generic/luaxml/luaxml.tex b/macros/luatex/generic/luaxml/luaxml.tex
index 562a298cb0..28539d898c 100644
--- a/macros/luatex/generic/luaxml/luaxml.tex
+++ b/macros/luatex/generic/luaxml/luaxml.tex
@@ -7,7 +7,7 @@
\usepackage{framed}
% Version is defined in the makefile, use default values when compiled directly
\ifdefined\version\else
-\def\version{v0.1p}
+\def\version{v0.1q}
\let\gitdate\date
\fi
\newcommand\modulename[1]{\subsection{#1}\label{sec:#1}}