[template-glib] template: dont swallow newlines after expression nodes
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [template-glib] template: dont swallow newlines after expression nodes
- Date: Fri, 6 May 2022 23:03:55 +0000 (UTC)
commit 8abddaa3aaad602df1d32fb42d65254e6475785c
Author: Christian Hergert <chergert redhat com>
Date: Fri May 6 16:02:23 2022 -0700
template: dont swallow newlines after expression nodes
Fixes #3
src/tmpl-token-input-stream.c | 10 ++++++++--
src/tmpl-token-private.h | 34 +++++++++++++++++++++++++++++++++
src/tmpl-token.c | 10 +++-------
tests/test-template-test1.tmpl | 4 +++-
tests/test-template-test1.tmpl.expected | 4 +++-
5 files changed, 51 insertions(+), 11 deletions(-)
---
diff --git a/src/tmpl-token-input-stream.c b/src/tmpl-token-input-stream.c
index cf381d5..84eed0d 100644
--- a/src/tmpl-token-input-stream.c
+++ b/src/tmpl-token-input-stream.c
@@ -16,7 +16,10 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
+#include "config.h"
+
#include "tmpl-token-input-stream.h"
+#include "tmpl-token-private.h"
struct _TmplTokenInputStream
{
@@ -186,6 +189,7 @@ tmpl_token_input_stream_read_token (TmplTokenInputStream *self,
GError **error)
{
GDataInputStream *stream = (GDataInputStream *)self;
+ TmplToken *ret;
GError *local_error = NULL;
gunichar ch;
gchar *text;
@@ -309,10 +313,12 @@ tmpl_token_input_stream_read_token (TmplTokenInputStream *self,
if (!(text = tmpl_token_input_stream_read_tag (self, &len, cancellable, error)))
return NULL;
- self->swallow_newline = TRUE;
+ ret = tmpl_token_new_generic (g_steal_pointer (&text));
+
+ self->swallow_newline = ret != NULL && ret->type != TMPL_TOKEN_EXPRESSION;
self->last_was_text_with_newline = FALSE;
- return tmpl_token_new_generic (text);
+ return ret;
}
/**
diff --git a/src/tmpl-token-private.h b/src/tmpl-token-private.h
new file mode 100644
index 0000000..a1f72c8
--- /dev/null
+++ b/src/tmpl-token-private.h
@@ -0,0 +1,34 @@
+/* tmpl-token-private.h
+ *
+ * Copyright (C) 2016 Christian Hergert <chergert redhat com>
+ *
+ * This file is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This file is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef TMPL_TOKEN_PRIVATE_H
+#define TMPL_TOKEN_PRIVATE_H
+
+#include "tmpl-token.h"
+
+G_BEGIN_DECLS
+
+struct _TmplToken
+{
+ TmplTokenType type;
+ gchar *text;
+};
+
+G_END_DECLS
+
+#endif /* TMPL_TOKEN_PRIVATE_H */
diff --git a/src/tmpl-token.c b/src/tmpl-token.c
index a12bee8..16ab375 100644
--- a/src/tmpl-token.c
+++ b/src/tmpl-token.c
@@ -20,16 +20,12 @@
# define _GNU_SOURCE
#endif
+#include "config.h"
+
#include <stdio.h>
#include <stdlib.h>
-#include "tmpl-token.h"
-
-struct _TmplToken
-{
- TmplTokenType type;
- gchar *text;
-};
+#include "tmpl-token-private.h"
static TmplToken *
tmpl_token_new (void)
diff --git a/tests/test-template-test1.tmpl b/tests/test-template-test1.tmpl
index ce09fa6..11c191e 100644
--- a/tests/test-template-test1.tmpl
+++ b/tests/test-template-test1.tmpl
@@ -1,6 +1,8 @@
<html>
<head>
- <title>{{title}}</title>
+ <title>
+ {{title}}
+ </title>
</head>
<body>
{{if title}}
diff --git a/tests/test-template-test1.tmpl.expected b/tests/test-template-test1.tmpl.expected
index 5d78fde..6daf042 100644
--- a/tests/test-template-test1.tmpl.expected
+++ b/tests/test-template-test1.tmpl.expected
@@ -1,6 +1,8 @@
<html>
<head>
- <title>My Title</title>
+ <title>
+ My Title
+ </title>
</head>
<body>
<h1>My Title</h1>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]