pub mod code;
pub mod emphasis;
pub mod link;
pub mod ruby;
pub mod semantic;
pub fn dispatch_inline_handler(
tag_name: &str,
node_handle: &tl::NodeHandle,
parser: &tl::Parser,
output: &mut String,
options: &crate::options::ConversionOptions,
ctx: &crate::converter::Context,
depth: usize,
dom_ctx: &crate::converter::DomContext,
) -> bool {
match tag_name {
"strong" | "b" | "em" | "i" => {
emphasis::handle(tag_name, node_handle, parser, output, options, ctx, depth, dom_ctx);
true
}
"a" => {
link::handle(node_handle, parser, output, options, ctx, depth, dom_ctx);
true
}
"code" | "kbd" | "samp" => {
code::handle(tag_name, node_handle, parser, output, options, ctx, depth, dom_ctx);
true
}
"mark" | "del" | "s" | "ins" | "u" | "small" | "sub" | "sup" | "var" | "dfn" | "abbr" | "span" => {
semantic::handle(tag_name, node_handle, parser, output, options, ctx, depth, dom_ctx);
true
}
"ruby" | "rb" | "rt" | "rp" | "rtc" => {
ruby::handle(tag_name, node_handle, parser, output, options, ctx, depth, dom_ctx);
true
}
_ => false,
}
}
#[cfg(test)]
mod tests {
#[test]
fn test_dispatcher_routes_emphasis_tags() {
assert!(matches!(
("strong", "strong"),
(tag, _) if matches!(tag, "strong" | "b" | "em" | "i")
));
assert!(matches!(
("em", "em"),
(tag, _) if matches!(tag, "strong" | "b" | "em" | "i")
));
}
#[test]
fn test_dispatcher_routes_code_tags() {
assert!(matches!(
("code", "code"),
(tag, _) if matches!(tag, "code" | "kbd" | "samp")
));
assert!(matches!(
("kbd", "kbd"),
(tag, _) if matches!(tag, "code" | "kbd" | "samp")
));
}
#[test]
fn test_dispatcher_routes_semantic_tags() {
assert!(matches!(
("mark", "mark"),
(tag, _) if matches!(tag, "mark" | "del" | "s" | "ins" | "u" | "small" | "sub" | "sup" | "var" | "dfn" | "abbr")
));
assert!(matches!(
("del", "del"),
(tag, _) if matches!(tag, "mark" | "del" | "s" | "ins" | "u" | "small" | "sub" | "sup" | "var" | "dfn" | "abbr")
));
assert!(matches!(
("sub", "sub"),
(tag, _) if matches!(tag, "mark" | "del" | "s" | "ins" | "u" | "small" | "sub" | "sup" | "var" | "dfn" | "abbr")
));
assert!(matches!(
("var", "var"),
(tag, _) if matches!(tag, "mark" | "del" | "s" | "ins" | "u" | "small" | "sub" | "sup" | "var" | "dfn" | "abbr")
));
assert!(matches!(
("dfn", "dfn"),
(tag, _) if matches!(tag, "mark" | "del" | "s" | "ins" | "u" | "small" | "sub" | "sup" | "var" | "dfn" | "abbr")
));
assert!(matches!(
("abbr", "abbr"),
(tag, _) if matches!(tag, "mark" | "del" | "s" | "ins" | "u" | "small" | "sub" | "sup" | "var" | "dfn" | "abbr")
));
}
#[test]
fn test_dispatcher_recognizes_link_tag() {
assert!(matches!(
("a", "a"),
(tag, _) if tag == "a"
));
}
#[test]
fn test_dispatcher_routes_ruby_tags() {
assert!(matches!(
("ruby", "ruby"),
(tag, _) if matches!(tag, "ruby" | "rb" | "rt" | "rp" | "rtc")
));
assert!(matches!(
("rt", "rt"),
(tag, _) if matches!(tag, "ruby" | "rb" | "rt" | "rp" | "rtc")
));
}
#[test]
fn test_unknown_tags_not_routed() {
let unknown_tags = vec!["div", "p", "section", "article", "table"];
for tag in unknown_tags {
assert!(matches!(
(tag, tag),
(tag, _) if !matches!(
tag,
"strong" | "b" | "em" | "i" | "a" | "code" | "kbd" | "samp"
| "mark" | "del" | "s" | "ins" | "u" | "small" | "sub" | "sup" | "var" | "dfn" | "abbr"
| "ruby" | "rb" | "rt" | "rp" | "rtc" | "span"
)
));
}
}
}