use super::walk_node;
pub fn handle_details(
_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() {
super::walk_node(child_handle, parser, output, options, ctx, depth, dom_ctx);
}
}
return;
}
let mut content = String::with_capacity(256);
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_summary(
_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 mut summary_ctx = ctx.clone();
if !ctx.convert_as_inline {
summary_ctx.in_strong = true;
}
let children = tag.children();
{
for child_handle in children.top().iter() {
super::walk_node(
child_handle,
parser,
&mut content,
options,
&summary_ctx,
depth + 1,
dom_ctx,
);
}
}
let trimmed = content.trim();
if !trimmed.is_empty() {
if ctx.convert_as_inline {
output.push_str(trimmed);
} else {
let mut symbol = String::with_capacity(2);
symbol.push(options.strong_em_symbol);
symbol.push(options.strong_em_symbol);
output.push_str(&symbol);
output.push_str(trimmed);
output.push_str(&symbol);
output.push_str("\n\n");
}
}
}
}
pub fn handle_dialog(
_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() {
super::walk_node(child_handle, parser, output, options, ctx, depth, dom_ctx);
}
}
return;
}
let content_start = output.len();
let children = tag.children();
{
for child_handle in children.top().iter() {
super::walk_node(child_handle, parser, output, options, ctx, depth, dom_ctx);
}
}
while output.len() > content_start && (output.ends_with(' ') || output.ends_with('\t')) {
output.pop();
}
if output.len() > content_start && !output.ends_with("\n\n") {
output.push_str("\n\n");
}
}
}
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 {
"details" => handle_details(tag_name, node_handle, parser, output, options, ctx, depth, dom_ctx),
"summary" => handle_summary(tag_name, node_handle, parser, output, options, ctx, depth, dom_ctx),
"dialog" => handle_dialog(tag_name, node_handle, parser, output, options, ctx, depth, dom_ctx),
_ => {}
}
}