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

Function parse_markdown_frontmatter

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

Source from the content-addressed store, hash-verified

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

Calls 2

yaml_frontmatter_to_jsonFunction · 0.85
lenMethod · 0.45