Find element by id

This commit is contained in:
Christoph Hagen 2022-09-23 09:22:00 +02:00
parent 6c21d8c857
commit fdd4c0e4d9

View File

@ -594,3 +594,21 @@ extension Element {
} }
} }
} }
extension Element {
/**
Find a page by its page ID within the tree of the element.
*/
func find(_ pageId: String) -> Element? {
if self.id == pageId {
return self
}
for child in elements {
if let found = child.find(pageId) {
return found
}
}
return nil
}
}