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

Function parse_markdown_frontmatter

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

Source from the content-addressed store, hash-verified

1251}
1252
1253fn parse_markdown_frontmatter(content: &str) -> (String, String) {
1254 // Check for frontmatter delimiter
1255 if !content.starts_with("---\n") && !content.starts_with("---\r\n") {
1256 return ("{}".to_string(), content.to_string());
1257 }
1258
1259 // Find closing delimiter
1260 let after_first = if content.starts_with("---\r\n") { 5 } else { 4 };
1261 let rest = &content[after_first..];
1262
1263 let (close_idx, skip_len) = if let Some(idx) = rest.find("\n---\n") {
1264 (idx, 5) // "\n---\n" is 5 bytes
1265 } else if let Some(idx) = rest.find("\n---\r\n") {
1266 (idx, 6) // "\n---\r\n" is 6 bytes
1267 } else if rest.ends_with("\n---") {
1268 (rest.len() - 3, 3)
1269 } else {
1270 // No closing delimiter — treat entire content as body
1271 return ("{}".to_string(), content.to_string());
1272 };
1273
1274 let yaml_str = &rest[..close_idx];
1275 let body_start = after_first + close_idx + skip_len;
1276 let body = if body_start <= content.len() {
1277 content[body_start..].to_string()
1278 } else {
1279 String::new()
1280 };
1281
1282 // Convert YAML frontmatter to JSON
1283 let frontmatter_json = yaml_frontmatter_to_json(yaml_str);
1284
1285 (frontmatter_json, body)
1286}
1287
1288fn frontmatter_json_equal(left: &str, right: &str) -> bool {
1289 match (

Calls 2

yaml_frontmatter_to_jsonFunction · 0.85
lenMethod · 0.45