From e32213f5e437abf86e203587a46e47b74331ce29 Mon Sep 17 00:00:00 2001 From: Daniel Silverstone Date: Tue, 4 Apr 2006 10:56:21 +0000 Subject: [project @ 2006-04-04 10:56:21 by dsilvers] New way to do the
 newline stripping to cope with tags in the 

svn path=/import/netsurf/; revision=2486
---
 render/box.c           |  1 +
 render/box.h           |  4 ++++
 render/box_construct.c | 36 ++++++++++++++++++++++++++++--------
 3 files changed, 33 insertions(+), 8 deletions(-)

diff --git a/render/box.c b/render/box.c
index 5ceb0376c..65c15fba3 100644
--- a/render/box.c
+++ b/render/box.c
@@ -67,6 +67,7 @@ struct box * box_create(struct css_style *style,
 	box->length = 0;
 	box->space = 0;
 	box->clone = 0;
+	box->strip_leading_newline = 0;
 	box->href = href;
 	box->target = target;
 	box->title = title;
diff --git a/render/box.h b/render/box.h
index 3c62ecffe..5a82830db 100644
--- a/render/box.h
+++ b/render/box.h
@@ -163,6 +163,10 @@ struct box {
 	/** This box is a continuation of the previous box (eg from line
 	 * breaking). */
 	unsigned int clone : 1;
+	/** This box represents a 
 tag which has not yet had its white
+	 * space stripped if possible
+	 */
+	unsigned int strip_leading_newline : 1;
 
 	char *href;   /**< Link, or 0. */
 	const char *target;  /**< Link target, or 0. */
diff --git a/render/box_construct.c b/render/box_construct.c
index b3e5e879d..1cb0ffb19 100644
--- a/render/box_construct.c
+++ b/render/box_construct.c
@@ -115,6 +115,7 @@ static bool box_frameset(BOX_SPECIAL_PARAMS);
 static bool box_select_add_option(struct form_control *control, xmlNode *n);
 static bool box_object(BOX_SPECIAL_PARAMS);
 static bool box_embed(BOX_SPECIAL_PARAMS);
+static bool box_pre(BOX_SPECIAL_PARAMS);
 /*static bool box_applet(BOX_SPECIAL_PARAMS);*/
 static bool box_iframe(BOX_SPECIAL_PARAMS);
 static bool box_get_attribute(xmlNode *n, const char *attribute,
@@ -141,6 +142,7 @@ static const struct element_entry element_table[] = {
 	{"img", box_image},
 	{"input", box_input},
 	{"object", box_object},
+	{"pre", box_pre},
 	{"select", box_select},
 	{"textarea", box_textarea}
 };
@@ -293,7 +295,13 @@ bool box_construct_element(xmlNode *n, struct content *content,
 	assert(inline_container);
 
 	gui_multitask();
-
+	
+	/* In case the parent is a pre block, we clear the
+	 * strip_leading_newline flag since it is not used if we
+	 * follow the pre with a tag
+	 */
+	parent->strip_leading_newline = 0;
+	
 	style = box_get_style(content, parent_style, n);
 	if (!style)
 		return false;
@@ -627,13 +635,16 @@ bool box_construct_text(xmlNode *n, struct content *content,
 		current = text;
 		
 		/* swallow a single leading new line */
-		switch (*current) {
-		case '\n':
-			current++; break;
-		case '\r':
-			current++;
-			if (*current == '\n') current++;
-			break;
+		if (parent->strip_leading_newline) {
+			switch (*current) {
+			case '\n':
+				current++; break;
+			case '\r':
+				current++;
+				if (*current == '\n') current++;
+				break;
+			}
+			parent->strip_leading_newline = 0;
 		}
 		
 		do {
@@ -1150,6 +1161,15 @@ bool box_br(BOX_SPECIAL_PARAMS)
 	return true;
 }
 
+/**
+ * Preformatted text [9.3.4].
+ */
+
+bool box_pre(BOX_SPECIAL_PARAMS)
+{
+	box->strip_leading_newline = 1;
+	return true;
+}
 
 /**
  * Anchor [12.2].
-- 
cgit v1.2.3