aboutsummaryrefslogtreecommitdiff
path: root/examples/ast_to_gemtext.rs
diff options
context:
space:
mode:
authorFuwn <[email protected]>2024-03-25 00:59:25 +0000
committerFuwn <[email protected]>2024-03-25 00:59:25 +0000
commit40680a3648cc7d598d428d6fe1752a2be9bfd547 (patch)
treec4ea43de3543995c0b81e1a982c8671479012fd5 /examples/ast_to_gemtext.rs
parentfeat(crate): bump version (diff)
downloadgerm-40680a3648cc7d598d428d6fe1752a2be9bfd547.tar.xz
germ-40680a3648cc7d598d428d6fe1752a2be9bfd547.zip
docs(examples): comment examples
Diffstat (limited to 'examples/ast_to_gemtext.rs')
-rw-r--r--examples/ast_to_gemtext.rs11
1 files changed, 10 insertions, 1 deletions
diff --git a/examples/ast_to_gemtext.rs b/examples/ast_to_gemtext.rs
index 4b96893..d163c8f 100644
--- a/examples/ast_to_gemtext.rs
+++ b/examples/ast_to_gemtext.rs
@@ -16,6 +16,9 @@
// Copyright (C) 2022-2022 Fuwn <[email protected]>
// SPDX-License-Identifier: GPL-3.0-only
+//! This example converts Gemtext into an abstract syntax tree and then back
+//! into Gemtext, demonstrating both Germ's parsing and generation capabilities.
+
const EXAMPLE_GEMTEXT: &str = r#"```This is alt-text
Here goes the pre-formatted text.
@@ -46,5 +49,11 @@ This is more text after a blank line.
That was a link without text."#;
fn main() {
- println!("{}", germ::ast::Ast::from_string(EXAMPLE_GEMTEXT).to_gemtext());
+ // Parse `EXAMPLE_GEMTEXT` into an abstract syntax tree
+ let ast = germ::ast::Ast::from_string(EXAMPLE_GEMTEXT);
+ // Convert the abstract syntax tree back to Gemtext
+ let gemtext = ast.to_gemtext();
+
+ // Print the Gemtext, identical to `EXAMPLE_GEMTEXT`
+ println!("{gemtext}");
}