diff options
author | Karl Berry <karl@freefriends.org> | 2018-02-09 00:16:06 +0000 |
---|---|---|
committer | Karl Berry <karl@freefriends.org> | 2018-02-09 00:16:06 +0000 |
commit | b2153506a41b9f934841bc0eb31dd9c3946b407b (patch) | |
tree | debea85a21708749fafa1748c894ab25b0e125e8 /Master/texmf-dist/tex/luatex/luaxml/luaxml-parse-query.lua | |
parent | e6304d3f0b0d72c2f38350d3ae4b4fa6bd862793 (diff) |
luaxml (8feb18)
git-svn-id: svn://tug.org/texlive/trunk@46570 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/tex/luatex/luaxml/luaxml-parse-query.lua')
-rw-r--r-- | Master/texmf-dist/tex/luatex/luaxml/luaxml-parse-query.lua | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/Master/texmf-dist/tex/luatex/luaxml/luaxml-parse-query.lua b/Master/texmf-dist/tex/luatex/luaxml/luaxml-parse-query.lua new file mode 100644 index 00000000000..95679670529 --- /dev/null +++ b/Master/texmf-dist/tex/luatex/luaxml/luaxml-parse-query.lua @@ -0,0 +1,43 @@ +-- Source: https://github.com/leafo/web_sanitize +-- Author: Leaf Corcoran +local R, S, V, P +do + local _obj_0 = require("lpeg") + R, S, V, P = _obj_0.R, _obj_0.S, _obj_0.V, _obj_0.P +end +local C, Cs, Ct, Cmt, Cg, Cb, Cc, Cp +do + local _obj_0 = require("lpeg") + C, Cs, Ct, Cmt, Cg, Cb, Cc, Cp = _obj_0.C, _obj_0.Cs, _obj_0.Ct, _obj_0.Cmt, _obj_0.Cg, _obj_0.Cb, _obj_0.Cc, _obj_0.Cp +end +local alphanum = R("az", "AZ", "09") +local num = R("09") +local white = S(" \t\n") ^ 0 +local word = (alphanum + S("_-")) ^ 1 +local mark +mark = function(name) + return function(...) + return { + name, + ... + } + end +end +local parse_query +parse_query = function(query) + local tag = word / mark("tag") + local cls = P(".") * (word / mark("class")) + local id = P("#") * (word / mark("id")) + local any = P("*") / mark("any") + local nth = P(":nth-child(") * C(num ^ 1) * ")" / mark("nth-child") + local first = P(":first-child") / mark("first-child") + local attr = P("[") * C(word) * P("]") / mark("attr") + local selector = Ct((any + nth + first + tag + cls + id + attr) ^ 1) + local pq = Ct(selector * (white * selector) ^ 0) + local pqs = Ct(pq * (white * P(",") * white * pq) ^ 0) + pqs = pqs * (white * -1) + return pqs:match(query) +end +return { + parse_query = parse_query +} |