···8282 ));
8383 }
84848585+ if source.chars().last().map_or(false, |c| c == '\n') {
8686+ if let Some(last) = ast.last() {
8787+ if !matches!(last, Node::Whitespace) {
8888+ ast.push(Node::Whitespace);
8989+ }
9090+ }
9191+ }
9292+8593 Self { inner: ast }
8694 }
8795···95103 /// // the original Gemtext.
96104 /// assert_eq!(
97105 /// germ::ast::Ast::from_nodes(
9898- /// germ::gemini_to_ast!("=> / Home\n").inner().to_vec()
106106+ /// germ::gemini_to_ast!("=> / Home").inner().to_vec()
99107 /// )
100108 /// .to_gemtext(),
101101- /// "=> / Home\n"
109109+ /// "=> / Home"
102110 /// );
103111 /// ```
104112 #[must_use]
···143151 )),
144152 Node::Whitespace => gemtext.push('\n'),
145153 }
154154+ }
155155+156156+ if gemtext.ends_with('\n') && !gemtext.ends_with("\n\n") {
157157+ gemtext.pop();
146158 }
147159148160 gemtext
···279291280292 break;
281293 }
282282- // This as a catchall, it does a number of things.
294294+ // This as a catchall. It does a number of things.
283295 _ => {
284296 if *in_preformatted {
285297 // If we are in a preformatted line context, add the line to the
+1-1
src/ast/macros.rs
···2626/// germ::gemini_to_ast!("=> / A link!").to_gemtext(),
2727/// // `to_gemtext` appends a newline to all responses, so let's make sure we
2828/// // account for that.
2929-/// format!("{}\n", "=> / A link!"),
2929+/// "=> / A link!",
3030/// );
3131#[macro_export]
3232macro_rules! gemini_to_ast {
+4-4
tests/ast.rs
···8888 Ast::from_string(EXAMPLE_GEMTEXT).to_gemtext(),
8989 // `to_gemtext` appends a newline to all responses, so let's make sure we
9090 // account for that.
9191- format!("{}\n", EXAMPLE_GEMTEXT),
9191+ EXAMPLE_GEMTEXT
9292 );
9393 }
9494···9898 germ::gemini_to_ast!(EXAMPLE_GEMTEXT).to_gemtext(),
9999 // `to_gemtext` appends a newline to all responses, so let's make sure we
100100 // account for that.
101101- format!("{}\n", EXAMPLE_GEMTEXT),
101101+ EXAMPLE_GEMTEXT
102102 );
103103 }
104104105105 #[test]
106106 fn gemtext_to_ast_then_node_to_ast_to_gemtext() {
107107 assert_eq!(
108108- Ast::from_nodes(germ::gemini_to_ast!("=> / Home\n").inner().to_vec())
108108+ Ast::from_nodes(germ::gemini_to_ast!("=> / Home").inner().to_vec())
109109 .to_gemtext(),
110110- "=> / Home\n"
110110+ "=> / Home"
111111 );
112112 }
113113}