use scraper::ElementRef;
use crate::context::Context;
use crate::converter::{Action, Rule};
use crate::dom;
#[derive(Debug, Clone, Copy)]
pub(super) struct Iframe;
impl Rule for Iframe {
fn tags(&self) -> &'static [&'static str] {
&["iframe"]
}
fn apply(&self, _content: &str, element: &ElementRef<'_>, ctx: &mut Context<'_>) -> Action {
let Some(src) = dom::attr(element, "src") else {
return Action::Replace(String::new());
};
if src.trim().is_empty() {
return Action::Replace(String::new());
}
if src.starts_with("data:") {
return Action::Replace(String::new());
}
let absolute_url = ctx.resolve_url(src);
Action::Replace(format!("[iframe]({absolute_url})"))
}
}