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

Function parse_markdown_frontmatter

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

Source from the content-addressed store, hash-verified

798}
799
800fn parse_markdown_frontmatter(content: &str) -> (String, String) {
801 // Check for frontmatter delimiter
802 if !content.starts_with("---\n") && !content.starts_with("---\r\n") {
803 return ("{}".to_string(), content.to_string());
804 }
805
806 // Find closing delimiter
807 let after_first = if content.starts_with("---\r\n") { 5 } else { 4 };
808 let rest = &content[after_first..];
809
810 let (close_idx, skip_len) = if let Some(idx) = rest.find("\n---\n") {
811 (idx, 5) // "\n---\n" is 5 bytes
812 } else if let Some(idx) = rest.find("\n---\r\n") {
813 (idx, 6) // "\n---\r\n" is 6 bytes
814 } else if rest.ends_with("\n---") {
815 (rest.len() - 3, 3)
816 } else {
817 // No closing delimiter — treat entire content as body
818 return ("{}".to_string(), content.to_string());
819 };
820
821 let yaml_str = &rest[..close_idx];
822 let body_start = after_first + close_idx + skip_len;
823 let body = if body_start <= content.len() {
824 content[body_start..].to_string()
825 } else {
826 String::new()
827 };
828
829 // Convert YAML frontmatter to JSON
830 let frontmatter_json = yaml_frontmatter_to_json(yaml_str);
831
832 (frontmatter_json, body)
833}
834
835/// Convert simple YAML frontmatter to a JSON string.
836///

Calls 2

yaml_frontmatter_to_jsonFunction · 0.85
lenMethod · 0.45