storkit: merge 427_story_server_side_text_normalization_for_chat_message_line_breaks

This commit is contained in:
dave
2026-03-28 10:39:13 +00:00
parent 1ae2fa9b9b
commit 52513b55ff
4 changed files with 196 additions and 1 deletions
+16 -1
View File
@@ -14,11 +14,12 @@ pub fn format_startup_announcement(bot_name: &str) -> String {
/// tasklists) so that common Markdown constructs render correctly in Matrix
/// clients such as Element.
pub fn markdown_to_html(markdown: &str) -> String {
let normalized = crate::chat::util::normalize_line_breaks(markdown);
let options = Options::ENABLE_TABLES
| Options::ENABLE_FOOTNOTES
| Options::ENABLE_STRIKETHROUGH
| Options::ENABLE_TASKLISTS;
let parser = Parser::new_ext(markdown, options);
let parser = Parser::new_ext(&normalized, options);
let mut html_output = String::new();
html::push_html(&mut html_output, parser);
html_output
@@ -80,6 +81,20 @@ mod tests {
);
}
#[test]
fn markdown_to_html_single_newline_prose_becomes_paragraphs() {
// Single newlines between prose sentences should produce separate paragraphs.
let html = markdown_to_html("Sentence one.\nSentence two.");
assert!(
html.contains("<p>Sentence one.</p>"),
"expected separate paragraph for first sentence: {html}"
);
assert!(
html.contains("<p>Sentence two.</p>"),
"expected separate paragraph for second sentence: {html}"
);
}
#[test]
fn startup_announcement_uses_bot_name() {
assert_eq!(format_startup_announcement("Timmy"), "Timmy is online.");