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

Function parse_markdown_frontmatter

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

Source from the content-addressed store, hash-verified

1102}
1103
1104fn parse_markdown_frontmatter(content: &str) -> (String, String) {
1105 // Check for frontmatter delimiter
1106 if !content.starts_with("---\n") && !content.starts_with("---\r\n") {
1107 return ("{}".to_string(), content.to_string());
1108 }
1109
1110 // Find closing delimiter
1111 let after_first = if content.starts_with("---\r\n") { 5 } else { 4 };
1112 let rest = &content[after_first..];
1113
1114 let (close_idx, skip_len) = if let Some(idx) = rest.find("\n---\n") {
1115 (idx, 5) // "\n---\n" is 5 bytes
1116 } else if let Some(idx) = rest.find("\n---\r\n") {
1117 (idx, 6) // "\n---\r\n" is 6 bytes
1118 } else if rest.ends_with("\n---") {
1119 (rest.len() - 3, 3)
1120 } else {
1121 // No closing delimiter — treat entire content as body
1122 return ("{}".to_string(), content.to_string());
1123 };
1124
1125 let yaml_str = &rest[..close_idx];
1126 let body_start = after_first + close_idx + skip_len;
1127 let body = if body_start <= content.len() {
1128 content[body_start..].to_string()
1129 } else {
1130 String::new()
1131 };
1132
1133 // Convert YAML frontmatter to JSON
1134 let frontmatter_json = yaml_frontmatter_to_json(yaml_str);
1135
1136 (frontmatter_json, body)
1137}
1138
1139fn frontmatter_json_equal(left: &str, right: &str) -> bool {
1140 match (

Calls 2

yaml_frontmatter_to_jsonFunction · 0.85
lenMethod · 0.45