@@ -81,6 +81,14 @@ pub const Node = struct {
8181 return t == .text ;
8282 }
8383
84+ pub fn text (n : Node ) ! ? []const u8 {
85+ const data = try parser .nodeTextContent (n .node );
86+ if (data == null ) return null ;
87+ if (data .? .len == 0 ) return null ;
88+
89+ return std .mem .trim (u8 , data .? , & std .ascii .whitespace );
90+ }
91+
8492 pub fn isEmptyText (n : Node ) ! bool {
8593 const data = try parser .nodeTextContent (n .node );
8694 if (data == null ) return true ;
@@ -216,13 +224,14 @@ test "Browser.CSS.Libdom: matchFirst" {
216224 .{ .q = "li, p" , .html = "<ul><li></li><li></li></ul><p>" , .exp = 1 },
217225 .{ .q = "p +/*This is a comment*/ p" , .html = "<p id=\" 1\" ><p id=\" 2\" ></p><address></address><p id=\" 3\" >" , .exp = 1 },
218226 // .{ .q = "p:contains(\"that wraps\")", .html = "<p>Text block that <span>wraps inner text</span> and continues</p>", .exp = 1 },
219- // .{ .q = "p:containsOwn(\"that wraps\")", .html = "<p>Text block that <span>wraps inner text</span> and continues</p>", .exp = 0 },
220- // .{ .q = ":containsOwn(\"inner\")", .html = "<p>Text block that <span>wraps inner text</span> and continues</p>", .exp = 1 },
221- // .{ .q = "p:containsOwn(\"block\")", .html = "<p>Text block that <span>wraps inner text</span> and continues</p>", .exp = 1 },
227+ .{ .q = "p:containsOwn(\" that wraps\" )" , .html = "<p>Text block that <span>wraps inner text</span> and continues</p>" , .exp = 0 },
228+ .{ .q = ":containsOwn(\" inner\" )" , .html = "<p>Text block that <span>wraps inner text</span> and continues</p>" , .exp = 1 },
229+ .{ .q = ":containsOwn(\" Inner\" )" , .html = "<p>Text block that <span>wraps inner text</span> and continues</p>" , .exp = 0 },
230+ .{ .q = "p:containsOwn(\" block\" )" , .html = "<p>Text block that <span>wraps inner text</span> and continues</p>" , .exp = 1 },
222231 // .{ .q = "div:has(#p1)", .html = "<div id=\"d1\"><p id=\"p1\"><span>text content</span></p></div><div id=\"d2\"/>", .exp = 1 },
223- // .{ .q = "div:has(:containsOwn(\"2\"))", .html = "<div id=\"d1\"><p id=\"p1\"><span>contents 1</span></p></div> <div id=\"d2\"><p>contents <em>2</em></p></div>", .exp = 1 },
224- // .{ .q = "body :has(:containsOwn(\"2\"))", .html = "<body><div id=\"d1\"><p id=\"p1\"><span>contents 1</span></p></div> <div id=\"d2\"><p id=\"p2\">contents <em>2</em></p></div></body>", .exp = 1 },
225- // .{ .q = "body :haschild(:containsOwn(\"2\"))", .html = "<body><div id=\"d1\"><p id=\"p1\"><span>contents 1</span></p></div> <div id=\"d2\"><p id=\"p2\">contents <em>2</em></p></div></body>", .exp = 1 },
232+ .{ .q = "div:has(:containsOwn(\" 2\" ))" , .html = "<div id=\" d1\" ><p id=\" p1\" ><span>contents 1</span></p></div> <div id=\" d2\" ><p>contents <em>2</em></p></div>" , .exp = 1 },
233+ .{ .q = "body :has(:containsOwn(\" 2\" ))" , .html = "<body><div id=\" d1\" ><p id=\" p1\" ><span>contents 1</span></p></div> <div id=\" d2\" ><p id=\" p2\" >contents <em>2</em></p></div></body>" , .exp = 1 },
234+ .{ .q = "body :haschild(:containsOwn(\" 2\" ))" , .html = "<body><div id=\" d1\" ><p id=\" p1\" ><span>contents 1</span></p></div> <div id=\" d2\" ><p id=\" p2\" >contents <em>2</em></p></div></body>" , .exp = 1 },
226235 // .{ .q = "p:matches([\\d])", .html = "<p id=\"p1\">0123456789</p><p id=\"p2\">abcdef</p><p id=\"p3\">0123ABCD</p>", .exp = 1 },
227236 // .{ .q = "p:matches([a-z])", .html = "<p id=\"p1\">0123456789</p><p id=\"p2\">abcdef</p><p id=\"p3\">0123ABCD</p>", .exp = 1 },
228237 // .{ .q = "p:matches([a-zA-Z])", .html = "<p id=\"p1\">0123456789</p><p id=\"p2\">abcdef</p><p id=\"p3\">0123ABCD</p>", .exp = 1 },
@@ -360,13 +369,14 @@ test "Browser.CSS.Libdom: matchAll" {
360369 .{ .q = "li, p" , .html = "<ul><li></li><li></li></ul><p>" , .exp = 3 },
361370 .{ .q = "p +/*This is a comment*/ p" , .html = "<p id=\" 1\" ><p id=\" 2\" ></p><address></address><p id=\" 3\" >" , .exp = 1 },
362371 // .{ .q = "p:contains(\"that wraps\")", .html = "<p>Text block that <span>wraps inner text</span> and continues</p>", .exp = 1 },
363- // .{ .q = "p:containsOwn(\"that wraps\")", .html = "<p>Text block that <span>wraps inner text</span> and continues</p>", .exp = 0 },
364- // .{ .q = ":containsOwn(\"inner\")", .html = "<p>Text block that <span>wraps inner text</span> and continues</p>", .exp = 1 },
365- // .{ .q = "p:containsOwn(\"block\")", .html = "<p>Text block that <span>wraps inner text</span> and continues</p>", .exp = 1 },
372+ .{ .q = "p:containsOwn(\" that wraps\" )" , .html = "<p>Text block that <span>wraps inner text</span> and continues</p>" , .exp = 0 },
373+ .{ .q = ":containsOwn(\" inner\" )" , .html = "<p>Text block that <span>wraps inner text</span> and continues</p>" , .exp = 1 },
374+ .{ .q = ":containsOwn(\" Inner\" )" , .html = "<p>Text block that <span>wraps inner text</span> and continues</p>" , .exp = 0 },
375+ .{ .q = "p:containsOwn(\" block\" )" , .html = "<p>Text block that <span>wraps inner text</span> and continues</p>" , .exp = 1 },
366376 .{ .q = "div:has(#p1)" , .html = "<div id=\" d1\" ><p id=\" p1\" ><span>text content</span></p></div><div id=\" d2\" />" , .exp = 1 },
367- // .{ .q = "div:has(:containsOwn(\"2\"))", .html = "<div id=\"d1\"><p id=\"p1\"><span>contents 1</span></p></div> <div id=\"d2\"><p>contents <em>2</em></p></div>", .exp = 1 },
368- // .{ .q = "body :has(:containsOwn(\"2\"))", .html = "<body><div id=\"d1\"><p id=\"p1\"><span>contents 1</span></p></div> <div id=\"d2\"><p id=\"p2\">contents <em>2</em></p></div></body>", .exp = 2 },
369- // .{ .q = "body :haschild(:containsOwn(\"2\"))", .html = "<body><div id=\"d1\"><p id=\"p1\"><span>contents 1</span></p></div> <div id=\"d2\"><p id=\"p2\">contents <em>2</em></p></div></body>", .exp = 1 },
377+ .{ .q = "div:has(:containsOwn(\" 2\" ))" , .html = "<div id=\" d1\" ><p id=\" p1\" ><span>contents 1</span></p></div> <div id=\" d2\" ><p>contents <em>2</em></p></div>" , .exp = 1 },
378+ .{ .q = "body :has(:containsOwn(\" 2\" ))" , .html = "<body><div id=\" d1\" ><p id=\" p1\" ><span>contents 1</span></p></div> <div id=\" d2\" ><p id=\" p2\" >contents <em>2</em></p></div></body>" , .exp = 2 },
379+ .{ .q = "body :haschild(:containsOwn(\" 2\" ))" , .html = "<body><div id=\" d1\" ><p id=\" p1\" ><span>contents 1</span></p></div> <div id=\" d2\" ><p id=\" p2\" >contents <em>2</em></p></div></body>" , .exp = 1 },
370380 // .{ .q = "p:matches([\\d])", .html = "<p id=\"p1\">0123456789</p><p id=\"p2\">abcdef</p><p id=\"p3\">0123ABCD</p>", .exp = 2 },
371381 // .{ .q = "p:matches([a-z])", .html = "<p id=\"p1\">0123456789</p><p id=\"p2\">abcdef</p><p id=\"p3\">0123ABCD</p>", .exp = 1 },
372382 // .{ .q = "p:matches([a-zA-Z])", .html = "<p id=\"p1\">0123456789</p><p id=\"p2\">abcdef</p><p id=\"p3\">0123ABCD</p>", .exp = 2 },
0 commit comments