🦠 The Definitive Gemini Protocol Toolkit
gemini gemini-protocol gemtext parser zero-dependency toolkit ast converter html markdown cli networking
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

feat: single Node gemtext content conversion

Fuwn 49898e1c a385a6d2

+36
+19
src/ast/container.rs
··· 85 85 Self { inner: ast } 86 86 } 87 87 88 + /// Build an AST tree from a [`Vec`] of [`Node`]s 89 + /// 90 + /// # Example 91 + /// 92 + /// ```rust 93 + /// // This assertion converts the Gemtext "=> / Home\n" to an AST tree of one 94 + /// // node, then converts the AST tree back to Gemtext, and compares it against 95 + /// // the original Gemtext. 96 + /// assert_eq!( 97 + /// germ::ast::Ast::from_nodes( 98 + /// germ::gemini_to_ast!("=> / Home\n").inner().to_vec() 99 + /// ) 100 + /// .to_gemtext(), 101 + /// "=> / Home\n" 102 + /// ); 103 + /// ``` 104 + #[must_use] 105 + pub fn from_nodes(nodes: Vec<Node>) -> Self { Self { inner: nodes } } 106 + 88 107 #[must_use] 89 108 pub fn to_gemtext(&self) -> String { 90 109 let mut gemtext = String::new();
+8
src/ast/node.rs
··· 171 171 /// A whitespace line, a line which contains nothing but whitespace. 172 172 Whitespace, 173 173 } 174 + 175 + impl Node { 176 + /// Obtain the Gemtext content of a single [`Node`] as a [`String`] 177 + #[must_use] 178 + pub fn content(&self) -> String { 179 + super::Ast::from_nodes(vec![self.to_owned()]).to_gemtext() 180 + } 181 + }
+9
tests/ast.rs
··· 101 101 format!("{}\n", EXAMPLE_GEMTEXT), 102 102 ); 103 103 } 104 + 105 + #[test] 106 + fn gemtext_to_ast_then_node_to_ast_to_gemtext() { 107 + assert_eq!( 108 + Ast::from_nodes(germ::gemini_to_ast!("=> / Home\n").inner().to_vec()) 109 + .to_gemtext(), 110 + "=> / Home\n" 111 + ); 112 + } 104 113 }