Split markdown content into optional YAML frontmatter and body.
(content: &str)
| 746 | |
| 747 | /// Split markdown content into optional YAML frontmatter and body. |
| 748 | fn split_frontmatter(content: &str) -> (Option<String>, String) { |
| 749 | let trimmed = content.trim_start(); |
| 750 | if !trimmed.starts_with("---") { |
| 751 | return (None, content.to_string()); |
| 752 | } |
| 753 | |
| 754 | // Find the closing --- |
| 755 | let after_first = &trimmed[3..]; |
| 756 | if let Some(end_idx) = after_first.find("\n---") { |
| 757 | let fm = after_first[..end_idx].trim().to_string(); |
| 758 | let body_start = end_idx + 4; // skip \n--- |
| 759 | let body = if body_start < after_first.len() { |
| 760 | after_first[body_start..].to_string() |
| 761 | } else { |
| 762 | String::new() |
| 763 | }; |
| 764 | (Some(fm), body) |
| 765 | } else { |
| 766 | (None, content.to_string()) |
| 767 | } |
| 768 | } |
| 769 | |
| 770 | /// Fallback sanitization for invalid YAML frontmatter. |
| 771 | /// Matches TS `ConfigMarkdown.fallbackSanitization`: if a top-level value |