| 1423 | } |
| 1424 | |
| 1425 | fn parse_markdown_frontmatter(content: &str) -> (String, String) { |
| 1426 | // Check for frontmatter delimiter |
| 1427 | if !content.starts_with("---\n") && !content.starts_with("---\r\n") { |
| 1428 | return ("{}".to_string(), content.to_string()); |
| 1429 | } |
| 1430 | |
| 1431 | // Find closing delimiter |
| 1432 | let after_first = if content.starts_with("---\r\n") { 5 } else { 4 }; |
| 1433 | let rest = &content[after_first..]; |
| 1434 | |
| 1435 | let (close_idx, skip_len) = if let Some(idx) = rest.find("\n---\n") { |
| 1436 | (idx, 5) // "\n---\n" is 5 bytes |
| 1437 | } else if let Some(idx) = rest.find("\n---\r\n") { |
| 1438 | (idx, 6) // "\n---\r\n" is 6 bytes |
| 1439 | } else if rest.ends_with("\n---") { |
| 1440 | (rest.len() - 3, 3) |
| 1441 | } else { |
| 1442 | // No closing delimiter — treat entire content as body |
| 1443 | return ("{}".to_string(), content.to_string()); |
| 1444 | }; |
| 1445 | |
| 1446 | let yaml_str = &rest[..close_idx]; |
| 1447 | let body_start = after_first + close_idx + skip_len; |
| 1448 | let body = if body_start <= content.len() { |
| 1449 | content[body_start..].to_string() |
| 1450 | } else { |
| 1451 | String::new() |
| 1452 | }; |
| 1453 | |
| 1454 | // Convert YAML frontmatter to JSON |
| 1455 | let frontmatter_json = yaml_frontmatter_to_json(yaml_str); |
| 1456 | |
| 1457 | (frontmatter_json, body) |
| 1458 | } |
| 1459 | |
| 1460 | fn frontmatter_json_equal(left: &str, right: &str) -> bool { |
| 1461 | match ( |