use regex::Regex;
pub(crate) fn apply_default_class(html: &str) -> String {
let table_pattern = Regex::new(r"<table>").unwrap();
table_pattern
.replace_all(html, "<table class=\"umd-list-table\">")
.to_string()
}
pub(crate) fn restore_markers(html: &str, tables: &[(String, String)]) -> String {
let mut result = html.to_string();
for (marker, table_html) in tables {
let marker_text = marker.trim();
let comrak_marker = format!("<p>{}</p>", marker_text);
result = result.replace(&comrak_marker, table_html);
}
result
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_apply_default_class() {
let input = "<table><tr><td>Cell</td></tr></table>";
let output = apply_default_class(input);
assert!(output.contains(r#"<table class="umd-list-table">"#));
}
#[test]
fn test_restore_markers() {
let tables = vec![(
"{{TABLE:0}}".to_string(),
"<table class=\"umd-table\"></table>".to_string(),
)];
let input = "<p>{{TABLE:0}}</p>";
let output = restore_markers(input, &tables);
assert_eq!(output, "<table class=\"umd-table\"></table>");
}
}