Skip to content

Commit

Permalink
Issue #133 - hopefully a better fix.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Geoff McLane committed Feb 12, 2015
1 parent 5d2cbd1 commit cff3fdd
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion src/pprint.c
Expand Up @@ -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. */
Expand Down

0 comments on commit cff3fdd

Please sign in to comment.