diff options
author | Karl Berry <karl@freefriends.org> | 2021-10-07 20:33:37 +0000 |
---|---|---|
committer | Karl Berry <karl@freefriends.org> | 2021-10-07 20:33:37 +0000 |
commit | e33d70fb04b016cc65621ba1907ecb4ddc8e650e (patch) | |
tree | cf2dd972aba6ac323a34e75a8d04308577ccb994 | |
parent | c764cdb0602ea9a4e41eea633127779c52b46290 (diff) |
luaxml (7oct21)
git-svn-id: svn://tug.org/texlive/trunk@60709 c570f23f-e606-0410-a88d-b1316a301751
-rw-r--r-- | Master/texmf-dist/doc/luatex/luaxml/README | 2 | ||||
-rw-r--r-- | Master/texmf-dist/doc/luatex/luaxml/luaxml.pdf | bin | 118178 -> 118191 bytes | |||
-rw-r--r-- | Master/texmf-dist/doc/luatex/luaxml/luaxml.tex | 2 | ||||
-rw-r--r-- | Master/texmf-dist/tex/luatex/luaxml/luaxml-cssquery.lua | 22 | ||||
-rw-r--r-- | Master/texmf-dist/tex/luatex/luaxml/luaxml-transform.lua | 9 |
5 files changed, 25 insertions, 10 deletions
diff --git a/Master/texmf-dist/doc/luatex/luaxml/README b/Master/texmf-dist/doc/luatex/luaxml/README index bea8ba60fc7..38ba6996863 100644 --- a/Master/texmf-dist/doc/luatex/luaxml/README +++ b/Master/texmf-dist/doc/luatex/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/Master/texmf-dist/doc/luatex/luaxml/luaxml.pdf b/Master/texmf-dist/doc/luatex/luaxml/luaxml.pdf Binary files differindex 89f9c3d1ed8..4f00cb6f69b 100644 --- a/Master/texmf-dist/doc/luatex/luaxml/luaxml.pdf +++ b/Master/texmf-dist/doc/luatex/luaxml/luaxml.pdf diff --git a/Master/texmf-dist/doc/luatex/luaxml/luaxml.tex b/Master/texmf-dist/doc/luatex/luaxml/luaxml.tex index 562a298cb01..28539d898c3 100644 --- a/Master/texmf-dist/doc/luatex/luaxml/luaxml.tex +++ b/Master/texmf-dist/doc/luatex/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}} 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 |