mirror of
https://github.com/msva/lua-htmlparser.git
synced 2024-11-27 12:44:22 +00:00
commit
550b39c87e
27
htmlparser-0.2-1.rockspec
Normal file
27
htmlparser-0.2-1.rockspec
Normal file
@ -0,0 +1,27 @@
|
||||
package = "htmlparser"
|
||||
version = "0.1-1"
|
||||
source = {
|
||||
url = "git://github.com/wscherphof/lua-htmlparser.git",
|
||||
branch = "v0.1"
|
||||
}
|
||||
description = {
|
||||
summary = "Parse HTML text into a tree of elements with selectors",
|
||||
detailed = [[
|
||||
Call parse() to build up a tree of element nodes. Each node in the tree, including the root node that is returned by parse(), supports a basic set of jQuery-like selectors. Or you could walk the tree by hand.
|
||||
]],
|
||||
homepage = "http://wscherphof.github.com/lua-htmlparser/",
|
||||
license = "MIT"
|
||||
}
|
||||
dependencies = {
|
||||
"lua >= 5.2",
|
||||
"set >= 0.1",
|
||||
"lunitx >= 0.6"
|
||||
}
|
||||
build = {
|
||||
type = "builtin",
|
||||
modules = {
|
||||
htmlparser = "src/htmlparser.lua",
|
||||
["htmlparser.ElementNode"] = "src/htmlparser/ElementNode.lua",
|
||||
["htmlparser.voidelements"] = "src/htmlparser/voidelements.lua"
|
||||
}
|
||||
}
|
@ -141,9 +141,10 @@ local function select(self, s)
|
||||
resultset = Set:new()
|
||||
for subject in pairs(subjects) do
|
||||
local star = subject.deepernodes
|
||||
if childrenonly then star = Set:new(subject.nodes) childrenonly = false end
|
||||
if childrenonly then star = Set:new(subject.nodes) end
|
||||
resultset = resultset + star
|
||||
end
|
||||
childrenonly = false
|
||||
if part == "*" then goto nextpart end
|
||||
local excludes, filter = Set:new()
|
||||
for t, w in string.gmatch(part,
|
||||
|
47
tst/init.lua
Normal file
47
tst/init.lua
Normal file
@ -0,0 +1,47 @@
|
||||
require("luarocks.loader")
|
||||
-- Omit next line in actual module clients; it's only to support development of the module itself
|
||||
package.path = "../src/?.lua;" .. package.path
|
||||
|
||||
local lunitx = require("lunitx")
|
||||
module("html", lunitx.testcase, package.seeall)
|
||||
|
||||
local htmlparser = require("htmlparser")
|
||||
local tree, sel
|
||||
|
||||
function test_descendants()
|
||||
tree = htmlparser.parse([[
|
||||
<parent>1
|
||||
<child>1.1</child>
|
||||
<child>1.2
|
||||
<child>1.2.1</child>
|
||||
</child>
|
||||
</parent>
|
||||
<parent>2
|
||||
<child>2.1</child>
|
||||
<child>2.2
|
||||
<child>2.2.1</child>
|
||||
</child>
|
||||
</parent>
|
||||
]])
|
||||
sel = tree("parent child")
|
||||
assert_equal(6, sel:len(), 'parent child')
|
||||
end
|
||||
|
||||
function test_children()
|
||||
tree = htmlparser.parse([[
|
||||
<parent>1
|
||||
<child>1.1</child>
|
||||
<child>1.2
|
||||
<child>1.2.1</child>
|
||||
</child>
|
||||
</parent>
|
||||
<parent>2
|
||||
<child>2.1</child>
|
||||
<child>2.2
|
||||
<child>2.2.1</child>
|
||||
</child>
|
||||
</parent>
|
||||
]])
|
||||
sel = tree("parent > child")
|
||||
assert_equal(4, sel:len(), 'parent > child')
|
||||
end
|
Loading…
Reference in New Issue
Block a user