use super::prelude::*;
use crate::tree::AnchorTarget;
pub const BLOCK_ANCHOR: BlockRule = BlockRule {
name: "block-anchor",
accepts_names: &["a", "anchor"],
accepts_special: true,
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 anchor block";
"in-head" => in_head,
"name" => name,
"special" => special,
);
assert_block_name(&BLOCK_ANCHOR, name);
let arguments = parser.get_head_map(&BLOCK_ANCHOR, in_head)?;
let attributes = arguments.to_hash_map();
let target = if special {
AnchorTarget::NewTab
} else {
AnchorTarget::Same
};
let (elements, exceptions) = parser.get_body_elements(&BLOCK_ANCHOR, false)?.into();
let element = Element::Anchor {
elements,
attributes,
target,
};
ok!(element, exceptions)
}