use super::walk_node;
pub fn handle_hgroup(
_tag_name: &str,
node_handle: &tl::NodeHandle,
parser: &tl::Parser,
output: &mut String,
options: &crate::options::ConversionOptions,
ctx: &super::Context,
depth: usize,
dom_ctx: &super::DomContext,
) {
if let Some(tl::Node::Tag(tag)) = node_handle.get(parser) {
let children = tag.children();
{
for child_handle in children.top().iter() {
walk_node(child_handle, parser, output, options, ctx, depth, dom_ctx);
}
}
}
}
pub fn handle_dl(
_tag_name: &str,
node_handle: &tl::NodeHandle,
parser: &tl::Parser,
output: &mut String,
options: &crate::options::ConversionOptions,
ctx: &super::Context,
depth: usize,
dom_ctx: &super::DomContext,
) {
if let Some(tl::Node::Tag(tag)) = node_handle.get(parser) {
if ctx.convert_as_inline {
let children = tag.children();
{
for child_handle in children.top().iter() {
walk_node(child_handle, parser, output, options, ctx, depth, dom_ctx);
}
}
return;
}
let mut content = String::new();
let children = tag.children();
{
for child_handle in children.top().iter() {
walk_node(child_handle, parser, &mut content, options, ctx, depth, dom_ctx);
}
}
let trimmed = content.trim();
if !trimmed.is_empty() {
if !output.is_empty() && !output.ends_with("\n\n") {
output.push_str("\n\n");
}
output.push_str(trimmed);
output.push_str("\n\n");
}
}
}
pub fn handle_dt(
_tag_name: &str,
node_handle: &tl::NodeHandle,
parser: &tl::Parser,
output: &mut String,
options: &crate::options::ConversionOptions,
ctx: &super::Context,
depth: usize,
dom_ctx: &super::DomContext,
) {
if let Some(tl::Node::Tag(tag)) = node_handle.get(parser) {
let mut content = String::with_capacity(64);
let children = tag.children();
{
for child_handle in children.top().iter() {
walk_node(child_handle, parser, &mut content, options, ctx, depth + 1, dom_ctx);
}
}
let trimmed = content.trim();
if !trimmed.is_empty() {
if ctx.convert_as_inline {
output.push_str(trimmed);
} else {
output.push_str(trimmed);
output.push('\n');
}
}
}
}
pub fn handle_dd(
_tag_name: &str,
node_handle: &tl::NodeHandle,
parser: &tl::Parser,
output: &mut String,
options: &crate::options::ConversionOptions,
ctx: &super::Context,
depth: usize,
dom_ctx: &super::DomContext,
) {
if let Some(tl::Node::Tag(tag)) = node_handle.get(parser) {
let mut content = String::with_capacity(128);
let children = tag.children();
{
for child_handle in children.top().iter() {
walk_node(child_handle, parser, &mut content, options, ctx, depth + 1, dom_ctx);
}
}
let trimmed = content.trim();
if ctx.convert_as_inline {
if !trimmed.is_empty() {
output.push_str(trimmed);
}
} else if !trimmed.is_empty() {
output.push_str(trimmed);
output.push_str("\n\n");
}
}
}
pub fn handle_menu(
_tag_name: &str,
node_handle: &tl::NodeHandle,
parser: &tl::Parser,
output: &mut String,
options: &crate::options::ConversionOptions,
ctx: &super::Context,
depth: usize,
dom_ctx: &super::DomContext,
) {
if let Some(tl::Node::Tag(tag)) = node_handle.get(parser) {
let content_start = output.len();
let menu_options = crate::options::ConversionOptions {
bullets: "-".to_string(),
..options.clone()
};
let list_ctx = super::Context {
in_ordered_list: false,
list_counter: 0,
in_list: true,
list_depth: ctx.list_depth,
..ctx.clone()
};
let children = tag.children();
{
for child_handle in children.top().iter() {
walk_node(child_handle, parser, output, &menu_options, &list_ctx, depth, dom_ctx);
}
}
if !ctx.convert_as_inline && output.len() > content_start {
if !output.ends_with("\n\n") {
if output.ends_with('\n') {
output.push('\n');
} else {
output.push_str("\n\n");
}
}
} else if ctx.convert_as_inline {
while output.ends_with('\n') {
output.pop();
}
}
}
}
pub fn handle(
tag_name: &str,
node_handle: &tl::NodeHandle,
parser: &tl::Parser,
output: &mut String,
options: &crate::options::ConversionOptions,
ctx: &super::Context,
depth: usize,
dom_ctx: &super::DomContext,
) {
match tag_name {
"hgroup" => handle_hgroup(tag_name, node_handle, parser, output, options, ctx, depth, dom_ctx),
"dl" => handle_dl(tag_name, node_handle, parser, output, options, ctx, depth, dom_ctx),
"dt" => handle_dt(tag_name, node_handle, parser, output, options, ctx, depth, dom_ctx),
"dd" => handle_dd(tag_name, node_handle, parser, output, options, ctx, depth, dom_ctx),
"menu" => handle_menu(tag_name, node_handle, parser, output, options, ctx, depth, dom_ctx),
_ => {}
}
}