From 326f2414fd402f0c1113c90044a105ad38e3e9dc Mon Sep 17 00:00:00 2001 From: Geoff McLane Date: Thu, 4 Jun 2015 13:11:54 +0200 Subject: [PATCH] Issue #212 - Further fix to set MixedContent in some cases. In certain circumstances a leading space has to be preverved to allow it to be used to create a text space node to insert before this element to preserve the view in a browser. And added a note asking why is ParseTag called with a hardcoded IgnoreWhitespace when some effort above has set the mode variable to MixedContent in certain cases, but need to think about this 2nd change. Also added some MSVC Debug output when this leading text is used to insert such a created text node before the element just to be reminded of this special event. --- src/parser.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/parser.c b/src/parser.c index 7821046..49bd4d4 100644 --- a/src/parser.c +++ b/src/parser.c @@ -516,6 +516,10 @@ static void TrimInitialSpace( TidyDocImpl* doc, Node *element, Node *text ) node->end = element->start; lexer->lexbuf[node->start] = ' '; TY_(InsertNodeBeforeElement)(element ,node); +#if !defined(NDEBUG) && defined(_MSC_VER) + SPRTF("TrimInitialSpace: Created text node, inserted before <%s>\n", + (element->element ? element->element : "unknown")); +#endif } } @@ -906,6 +910,13 @@ void TY_(ParseBlock)( TidyDocImpl* doc, Node *element, GetTokenMode mode) { mode = IgnoreWhitespace; } + else if (mode == IgnoreWhitespace) + { + /* Issue #212 - Further fix in case ParseBlock() is called with 'IgnoreWhitespace' + when such a leading space may need to be inserted before this element to + preverve the browser view */ + mode = MixedContent; + } while ((node = TY_(GetToken)(doc, mode /*MixedContent*/)) != NULL) { @@ -1355,6 +1366,9 @@ void TY_(ParseBlock)( TidyDocImpl* doc, Node *element, GetTokenMode mode) if (node->implicit) TY_(ReportError)(doc, element, node, INSERTING_TAG ); + /* Issue #212 - WHY is this hard coded to 'IgnoreWhitespace' while an + effort has been made above to set a 'MixedContent' mode in some cases? + WHY IS THE 'mode' VARIABLE NOT USED HERE???? */ ParseTag( doc, node, IgnoreWhitespace /*MixedContent*/ ); continue; }