pub fn fix_html_comment_fences(s: &str) -> StringExpand description
Fixes HTML comment closing fences to prevent content loss.
According to CommonMark, HTML block type 2 (comments) ends with the line containing -->.
This means any text on the same line after --> is included in the HTML block and would
be discarded by markdown parsers that ignore HTML blocks.
This function inserts a newline after --> when followed by non-whitespace content,
ensuring the trailing text is parsed as regular markdown.
ยงExamples
use quillmark_core::normalize::fix_html_comment_fences;
// Text on same line as --> is moved to next line
assert_eq!(
fix_html_comment_fences("<!-- comment -->Some text"),
"<!-- comment -->\nSome text"
);
// Already on separate line - no change
assert_eq!(
fix_html_comment_fences("<!-- comment -->\nSome text"),
"<!-- comment -->\nSome text"
);
// Only whitespace after --> - no change needed
assert_eq!(
fix_html_comment_fences("<!-- comment --> \nSome text"),
"<!-- comment --> \nSome text"
);
// Multi-line comments with trailing text
assert_eq!(
fix_html_comment_fences("<!--\nmultiline\n-->Trailing text"),
"<!--\nmultiline\n-->\nTrailing text"
);