use crate::converter::utility::content::chomp_inline;
pub fn handle_dfn(
_tag_name: &str,
node_handle: &tl::NodeHandle,
parser: &crate::tl_types::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(32);
let children = tag.children();
{
for child_handle in children.top().iter() {
super::walk_node(
child_handle,
parser,
&mut content,
options,
ctx,
depth + 1,
dom_ctx,
);
}
}
let (prefix, suffix, trimmed) = chomp_inline(&content);
if !trimmed.is_empty() {
output.push_str(prefix);
output.push(options.strong_em_symbol);
output.push_str(trimmed);
output.push(options.strong_em_symbol);
append_inline_suffix(
output,
suffix,
!trimmed.is_empty(),
node_handle,
parser,
dom_ctx,
);
}
}
}
pub fn handle_abbr(
_tag_name: &str,
node_handle: &tl::NodeHandle,
parser: &crate::tl_types::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(32);
let children = tag.children();
{
for child_handle in children.top().iter() {
super::walk_node(
child_handle,
parser,
&mut content,
options,
ctx,
depth + 1,
dom_ctx,
);
}
}
let trimmed = content.trim();
if !trimmed.is_empty() {
output.push_str(trimmed);
if let Some(title) = tag
.attributes()
.get("title")
.flatten()
.map(|v| v.as_utf8_str())
{
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: &crate::tl_types::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() {
super::walk_node(
child_handle,
parser,
output,
options,
ctx,
depth + 1,
dom_ctx,
);
}
}
}
}
pub fn handle_cite(
_tag_name: &str,
node_handle: &tl::NodeHandle,
parser: &crate::tl_types::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(32);
let children = tag.children();
{
for child_handle in children.top().iter() {
super::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('*');
output.push_str(trimmed);
output.push('*');
}
}
}
}
pub fn handle_q(
_tag_name: &str,
node_handle: &tl::NodeHandle,
parser: &crate::tl_types::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(32);
let children = tag.children();
{
for child_handle in children.top().iter() {
super::walk_node(
child_handle,
parser,
&mut content,
options,
ctx,
depth + 1,
dom_ctx,
);
}
}
let trimmed = content.trim();
if !trimmed.is_empty() {
output.push('"');
output.push_str(trimmed);
output.push('"');
}
}
}
pub fn handle(
tag_name: &str,
node_handle: &tl::NodeHandle,
parser: &crate::tl_types::Parser,
output: &mut String,
options: &crate::options::ConversionOptions,
ctx: &super::Context,
depth: usize,
dom_ctx: &super::DomContext,
) {
match tag_name {
"dfn" => handle_dfn(
tag_name,
node_handle,
parser,
output,
options,
ctx,
depth,
dom_ctx,
),
"abbr" => handle_abbr(
tag_name,
node_handle,
parser,
output,
options,
ctx,
depth,
dom_ctx,
),
"time" | "data" => handle_time_data(
tag_name,
node_handle,
parser,
output,
options,
ctx,
depth,
dom_ctx,
),
"cite" => handle_cite(
tag_name,
node_handle,
parser,
output,
options,
ctx,
depth,
dom_ctx,
),
"q" => handle_q(
tag_name,
node_handle,
parser,
output,
options,
ctx,
depth,
dom_ctx,
),
_ => {}
}
}
fn append_inline_suffix(
output: &mut String,
suffix: &str,
_is_nonempty: bool,
_node_handle: &tl::NodeHandle,
_parser: &crate::tl_types::Parser,
_dom_ctx: &super::DomContext,
) {
output.push_str(suffix);
}