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

Function parse_markdown_frontmatter

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

Source from the content-addressed store, hash-verified

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

Calls 2

yaml_frontmatter_to_jsonFunction · 0.85
lenMethod · 0.45