From cff3fdd30846fdd5d24274f0d9921aa5b5847007 Mon Sep 17 00:00:00 2001 From: Geoff McLane Date: Thu, 12 Feb 2015 15:20:16 +0100 Subject: [PATCH] Issue #133 - hopefully a better fix. As predicted the previous fix had adverse consequences on say script text, which then lost the indent, and was reverted. This introduces a new service, nodeIsTextLike, which naturally returns yes if it is text, but also is an AspTag. Maybe other text like nodes need to be added. --- src/pprint.c | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/src/pprint.c b/src/pprint.c index ae6336a..4f43db4 100644 --- a/src/pprint.c +++ b/src/pprint.c @@ -1732,10 +1732,29 @@ static int TextEndsWithNewline(Lexer *lexer, Node *node, uint mode ) return -1; } +/*\ + * Issue #133 - creeping indent - a very OLD bug - 2nd tidy run increases the indent! + * If the node is text, then remove any white space equal to the indent, + * but this also applies to the AspTag, which is text like... + * And may apply to other text like nodes as well. + * + * Here the total white space is returned, and then a sister service, IncrWS() + * will advance the start of the lexer output by the amount of the indent. +\*/ +static Bool TY_(nodeIsTextLike)( Node *node ) +{ + if ( TY_(nodeIsText)(node) ) + return yes; + if ( node->type == AspTag ) + return yes; + /* add other text like nodes... */ + return no; +} + static int TextStartsWithWhitespace( Lexer *lexer, Node *node, uint start, uint mode ) { assert( node != NULL ); - if ( (mode & (CDATA|COMMENT)) && TY_(nodeIsText)(node) && node->end > node->start && start >= node->start ) + if ( (mode & (CDATA|COMMENT)) && TY_(nodeIsTextLike)(node) && node->end > node->start && start >= node->start ) { uint ch, ix = start; /* Skip whitespace. */