tablo_test/protocol/
list_tabs.rs1use super::dom::{attr_value, tags_where};
5
6#[derive(Debug, Clone, PartialEq, Eq)]
8pub struct TabLink {
9 pub key: String,
11 pub active: bool,
13 pub count: Option<u64>,
15 pub href: String,
17}
18
19pub fn tab_links(html: &str) -> Vec<TabLink> {
21 tags_where(html, |tag, attrs| {
22 tag == "a" && attr_value(attrs, "data-list-tab").is_some()
23 })
24 .into_iter()
25 .map(|(_, attrs, inner)| TabLink {
26 key: attr_value(&attrs, "data-list-tab").unwrap_or_default(),
27 active: attr_value(&attrs, "aria-current").as_deref() == Some("page"),
28 count: tags_where(&inner, |_, attrs| {
29 attr_value(attrs, "data-list-tab-count").is_some()
30 })
31 .into_iter()
32 .next()
33 .and_then(|(_, attrs, _)| attr_value(&attrs, "data-list-tab-count")?.parse().ok()),
34 href: attr_value(&attrs, "href").unwrap_or_default(),
35 })
36 .collect()
37}