use super::prelude::*;
use std::borrow::Cow;
pub const BLOCK_SIZE: BlockRule = BlockRule {
name: "block-size",
accepts_names: &["size"],
accepts_special: false,
accepts_newlines: false,
parse_fn,
};
fn parse_fn<'r, 't>(
log: &slog::Logger,
parser: &mut Parser<'r, 't>,
name: &'t str,
special: bool,
in_head: bool,
) -> ParseResult<'r, 't, Elements<'t>> {
debug!(
log,
"Parsing size block";
"in-head" => in_head,
"name" => name,
);
assert_eq!(special, false, "Size doesn't allow special variant");
assert_block_name(&BLOCK_SIZE, name);
let size =
parser.get_head_value(&BLOCK_SIZE, in_head, |parser, value| match value {
Some(size) => Ok(format!("font-size: {};", size)),
None => Err(parser.make_warn(ParseWarningKind::BlockMissingArguments)),
})?;
let (elements, exceptions) = parser.get_body_elements(&BLOCK_SIZE, false)?.into();
let element = Element::StyledContainer(StyledContainer::new(
StyledContainerType::Size,
elements,
hashmap! {
Cow::Borrowed("style") => Cow::Owned(size),
},
));
ok!(element, exceptions)
}