MCPcopy Create free account
hub / github.com/atomicdotdev/atomic / parse_markdown_frontmatter

Function parse_markdown_frontmatter

atomic-repository/src/repository/vault.rs:1425–1458  ·  view source on GitHub ↗
(content: &str)

Source from the content-addressed store, hash-verified

1423}
1424
1425fn 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
1460fn frontmatter_json_equal(left: &str, right: &str) -> bool {
1461 match (

Calls 2

yaml_frontmatter_to_jsonFunction · 0.85
lenMethod · 0.45