use crate::converter::utility::content::chomp_inline;
pub fn handle_dfn(
_tag_name: &str,
node_handle: &tl::NodeHandle,
parser: &tl::Parser,
output: &mut String,
handler: super::HandlerContext<'_>,
) {
if let Some(tl::Node::Tag(tag)) = node_handle.get(parser) {
let mut content = String::with_capacity(32);
let children = tag.children();
{
for child_handle in children.top().iter() {
super::walk_node(
child_handle,
parser,
&mut content,
crate::converter::block::container::HandlerContext::new(
handler.options,
handler.ctx,
handler.depth + 1,
handler.dom_ctx,
),
);
}
}
let (prefix, suffix, trimmed) = chomp_inline(&content);
if !trimmed.is_empty() {
output.push_str(prefix);
output.push(handler.options.strong_em_symbol);
output.push_str(trimmed);
output.push(handler.options.strong_em_symbol);
append_inline_suffix(
output,
suffix,
!trimmed.is_empty(),
node_handle,
parser,
handler.dom_ctx,
);
}
}
}
pub fn handle_abbr(
_tag_name: &str,
node_handle: &tl::NodeHandle,
parser: &tl::Parser,
output: &mut String,
handler: super::HandlerContext<'_>,
) {
if let Some(tl::Node::Tag(tag)) = node_handle.get(parser) {
let mut content = String::with_capacity(32);
let children = tag.children();
{
for child_handle in children.top().iter() {
super::walk_node(
child_handle,
parser,
&mut content,
crate::converter::block::container::HandlerContext::new(
handler.options,
handler.ctx,
handler.depth + 1,
handler.dom_ctx,
),
);
}
}
let trimmed = content.trim();
if !trimmed.is_empty() {
output.push_str(trimmed);
if let Some(title) = crate::converter::utility::attributes::decoded_attribute(tag, "title") {
let trimmed_title = title.trim();
if !trimmed_title.is_empty() {
output.push_str(" (");
output.push_str(trimmed_title);
output.push(')');
}
}
}
}
}
pub fn handle_time_data(
_tag_name: &str,
node_handle: &tl::NodeHandle,
parser: &tl::Parser,
output: &mut String,
handler: super::HandlerContext<'_>,
) {
if let Some(tl::Node::Tag(tag)) = node_handle.get(parser) {
let children = tag.children();
{
for child_handle in children.top().iter() {
super::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_cite(
_tag_name: &str,
node_handle: &tl::NodeHandle,
parser: &tl::Parser,
output: &mut String,
handler: super::HandlerContext<'_>,
) {
if let Some(tl::Node::Tag(tag)) = node_handle.get(parser) {
let mut content = String::with_capacity(32);
let children = tag.children();
{
for child_handle in children.top().iter() {
super::walk_node(
child_handle,
parser,
&mut content,
crate::converter::block::container::HandlerContext::new(
handler.options,
handler.ctx,
handler.depth + 1,
handler.dom_ctx,
),
);
}
}
let trimmed = content.trim();
if !trimmed.is_empty() {
if handler.ctx.convert_as_inline {
output.push_str(trimmed);
} else {
output.push('*');
output.push_str(trimmed);
output.push('*');
}
}
}
}
pub fn handle_q(
_tag_name: &str,
node_handle: &tl::NodeHandle,
parser: &tl::Parser,
output: &mut String,
handler: super::HandlerContext<'_>,
) {
if let Some(tl::Node::Tag(tag)) = node_handle.get(parser) {
let mut content = String::with_capacity(32);
let children = tag.children();
{
let q_ctx = super::Context {
text_in_markers: true,
..handler.ctx.clone()
};
for child_handle in children.top().iter() {
super::walk_node(
child_handle,
parser,
&mut content,
crate::converter::block::container::HandlerContext::new(
handler.options,
&q_ctx,
handler.depth + 1,
handler.dom_ctx,
),
);
}
}
let trimmed = content.trim();
if trimmed.is_empty() {
if !content.is_empty() {
crate::converter::inline::wrapped::emit_whitespace_only_inline_body(&content, output);
}
return;
}
output.push('"');
output.push_str(trimmed);
output.push('"');
}
}
pub fn handle(
tag_name: &str,
node_handle: &tl::NodeHandle,
parser: &tl::Parser,
output: &mut String,
handler: super::HandlerContext<'_>,
) {
match tag_name {
"dfn" => handle_dfn(tag_name, node_handle, parser, output, handler),
"abbr" => handle_abbr(tag_name, node_handle, parser, output, handler),
"time" | "data" => handle_time_data(tag_name, node_handle, parser, output, handler),
"cite" => handle_cite(tag_name, node_handle, parser, output, handler),
"q" => handle_q(tag_name, node_handle, parser, output, handler),
_ => {}
}
}
fn append_inline_suffix(
output: &mut String,
suffix: &str,
_is_nonempty: bool,
_node_handle: &tl::NodeHandle,
_parser: &tl::Parser,
_dom_ctx: &super::DomContext,
) {
output.push_str(suffix);
}