mirror of
https://github.com/lightpanda-io/browser.git
synced 2026-03-22 04:34:44 +00:00
markdown: refactor content discovery to use TreeWalker
This commit is contained in:
@@ -20,6 +20,7 @@ const std = @import("std");
|
|||||||
|
|
||||||
const Page = @import("Page.zig");
|
const Page = @import("Page.zig");
|
||||||
const URL = @import("URL.zig");
|
const URL = @import("URL.zig");
|
||||||
|
const TreeWalker = @import("webapi/TreeWalker.zig");
|
||||||
const CData = @import("webapi/CData.zig");
|
const CData = @import("webapi/CData.zig");
|
||||||
const Element = @import("webapi/Element.zig");
|
const Element = @import("webapi/Element.zig");
|
||||||
const Node = @import("webapi/Node.zig");
|
const Node = @import("webapi/Node.zig");
|
||||||
@@ -114,26 +115,24 @@ fn isAllWhitespace(text: []const u8) bool {
|
|||||||
} else true;
|
} else true;
|
||||||
}
|
}
|
||||||
|
|
||||||
fn hasBlockDescendant(node: *Node) bool {
|
fn hasBlockDescendant(root: *Node) bool {
|
||||||
var it = node.childrenIterator();
|
var tw = TreeWalker.FullExcludeSelf.Elements.init(root, .{});
|
||||||
return while (it.next()) |child| {
|
while (tw.next()) |el| {
|
||||||
if (child.is(Element)) |el| {
|
if (isBlock(el.getTag())) return true;
|
||||||
if (isBlock(el.getTag())) break true;
|
}
|
||||||
if (hasBlockDescendant(child)) break true;
|
return false;
|
||||||
}
|
|
||||||
} else false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn hasVisibleContent(node: *Node) bool {
|
fn hasVisibleContent(root: *Node) bool {
|
||||||
var it = node.childrenIterator();
|
var tw = TreeWalker.FullExcludeSelf.init(root, .{});
|
||||||
while (it.next()) |child| {
|
while (tw.next()) |node| {
|
||||||
if (isSignificantText(child)) return true;
|
if (isSignificantText(node)) return true;
|
||||||
if (child.is(Element)) |el| {
|
if (node.is(Element)) |el| {
|
||||||
if (!isVisibleElement(el)) continue;
|
if (!isVisibleElement(el)) {
|
||||||
// Images are visible
|
tw.skipChildren();
|
||||||
if (el.getTag() == .img) return true;
|
} else if (el.getTag() == .img) {
|
||||||
// Recursive check
|
return true;
|
||||||
if (hasVisibleContent(child)) return true;
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
Reference in New Issue
Block a user