use crate::options::ConversionOptions;
use tl::{NodeHandle, Parser};
type Context = crate::converter::Context;
type DomContext = crate::converter::DomContext;
#[derive(Clone, Copy)]
pub struct HandlerContext<'a> {
pub options: &'a ConversionOptions,
pub ctx: &'a Context,
pub depth: usize,
pub dom_ctx: &'a DomContext,
}
impl<'a> HandlerContext<'a> {
pub const fn new(options: &'a ConversionOptions, ctx: &'a Context, depth: usize, dom_ctx: &'a DomContext) -> Self {
Self {
options,
ctx,
depth,
dom_ctx,
}
}
}
pub fn handle_structural_container(
node_handle: &NodeHandle,
parser: &Parser,
output: &mut String,
handler: HandlerContext<'_>,
) {
let Some(node) = node_handle.get(parser) else {
return;
};
let tl::Node::Tag(tag) = node else {
return;
};
let children = tag.children();
for child_handle in children.top().iter() {
crate::converter::main::walk_node(
child_handle,
parser,
output,
crate::converter::block::container::HandlerContext::new(
handler.options,
handler.ctx,
handler.depth + 1,
handler.dom_ctx,
),
);
}
}
pub fn handle_passthrough(node_handle: &NodeHandle, parser: &Parser, output: &mut String, handler: HandlerContext<'_>) {
let Some(node) = node_handle.get(parser) else {
return;
};
let tl::Node::Tag(tag) = node else {
return;
};
let children = tag.children();
for child_handle in children.top().iter() {
crate::converter::main::walk_node(
child_handle,
parser,
output,
crate::converter::block::container::HandlerContext::new(
handler.options,
handler.ctx,
handler.depth + 1,
handler.dom_ctx,
),
);
}
}
#[inline]
pub const fn handle_noop() {}