ftml/parsing/rule/impls/block/blocks/
iframe.rs1use super::prelude::*;
22use crate::url::is_url;
23
24pub const BLOCK_IFRAME: BlockRule = BlockRule {
25 name: "block-iframe",
26 accepts_names: &["iframe"],
27 accepts_star: false,
28 accepts_score: false,
29 accepts_newlines: true,
30 parse_fn,
31};
32
33fn parse_fn<'r, 't>(
34 parser: &mut Parser<'r, 't>,
35 name: &'t str,
36 flag_star: bool,
37 flag_score: bool,
38 in_head: bool,
39) -> ParseResult<'r, 't, Elements<'t>> {
40 debug!("Parsing iframe block (in-head {in_head})");
41 assert!(!flag_star, "iframe doesn't allow star flag");
42 assert!(!flag_score, "iframe doesn't allow score flag");
43 assert_block_name(&BLOCK_IFRAME, name);
44
45 let (url, arguments) = parser.get_head_name_map(&BLOCK_IFRAME, in_head)?;
46 if !is_url(url) {
47 warn!("Iframe block references non-URL: {url}");
48 return Err(parser.make_err(ParseErrorKind::BlockMalformedArguments));
49 }
50
51 let element = Element::Iframe {
52 url: cow!(url),
53 attributes: arguments.to_attribute_map(parser.settings()),
54 };
55
56 ok!(element)
57}