Something went wrong. Try again.
Flashcards over the wire
Something went wrong. Try again.
12345678910111213141516171819202122232425262728293031323334353637383940use crate::deck::note::Field;use crate::parse::syntax::{FlashSyntaxNode, SyntaxKind, child, child_token_text, children, direct_tokens, node_text};
pub fn parse_field<'a>(field_node: &'a FlashSyntaxNode) -> Field<'a> { let name = child(field_node, SyntaxKind::FieldHeader) .and_then(|header| child(&header, SyntaxKind::FieldName)) .map(|field_name| node_text(&field_name).trim().to_string()) .unwrap_or_default();
let content = child_token_text(field_node, SyntaxKind::Content) .map(|raw| raw.trim()) .unwrap_or("");
Field { name, content }}
pub fn parse_tags(tags_node: &FlashSyntaxNode) -> Vec<String> { children(tags_node, SyntaxKind::Tag) .map(|tag| node_text(&tag).trim().to_string()) .filter(|tag| !tag.is_empty()) .collect()}
pub fn parse_references(references_node: &FlashSyntaxNode) -> Vec<String> { children(references_node, SyntaxKind::Reference) .map(|reference| { node_text(&reference).trim().trim_start_matches('@').trim().to_string() }) .filter(|s| !s.is_empty()) .collect()}
pub fn parse_alias(alias_node: &FlashSyntaxNode) -> Option<(String, String)> { let words = direct_tokens(alias_node, SyntaxKind::Text); match words.as_slice() { [_, from, _, to, ..] => Some(((*from).to_string(), (*to).to_string())), _ => None, }}