diff options
| author | Fuwn <[email protected]> | 2024-06-19 07:13:56 +0000 |
|---|---|---|
| committer | Fuwn <[email protected]> | 2024-06-19 07:13:56 +0000 |
| commit | 49898e1c1214470e2684e661b558ee198fba18f0 (patch) | |
| tree | d8f7f96f5604aa028fa246919bc98ce3c8ae690d /src/ast/container.rs | |
| parent | deps(rustc): bump rust toolchain (diff) | |
| download | germ-49898e1c1214470e2684e661b558ee198fba18f0.tar.xz germ-49898e1c1214470e2684e661b558ee198fba18f0.zip | |
feat: single Node gemtext content conversion
Diffstat (limited to 'src/ast/container.rs')
| -rw-r--r-- | src/ast/container.rs | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/src/ast/container.rs b/src/ast/container.rs index 51931c6..d8f2817 100644 --- a/src/ast/container.rs +++ b/src/ast/container.rs @@ -85,6 +85,25 @@ impl Ast { Self { inner: ast } } + /// Build an AST tree from a [`Vec`] of [`Node`]s + /// + /// # Example + /// + /// ```rust + /// // This assertion converts the Gemtext "=> / Home\n" to an AST tree of one + /// // node, then converts the AST tree back to Gemtext, and compares it against + /// // the original Gemtext. + /// assert_eq!( + /// germ::ast::Ast::from_nodes( + /// germ::gemini_to_ast!("=> / Home\n").inner().to_vec() + /// ) + /// .to_gemtext(), + /// "=> / Home\n" + /// ); + /// ``` + #[must_use] + pub fn from_nodes(nodes: Vec<Node>) -> Self { Self { inner: nodes } } + #[must_use] pub fn to_gemtext(&self) -> String { let mut gemtext = String::new(); |