small refactoring in HTMLParser
This commit is contained in:
parent
f23cabfb2f
commit
abe349be34
|
@ -1862,55 +1862,6 @@ void HTMLParser::CheckDifferentContentExceptions(Item & item)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void HTMLParser::AddForgottenTags()
|
|
||||||
{
|
|
||||||
int i;
|
|
||||||
|
|
||||||
if( stack_len < 3 )
|
|
||||||
{
|
|
||||||
PopStack();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// we have forgotten to close some tags
|
|
||||||
|
|
||||||
// looking whether there is a matching opening tag
|
|
||||||
for(i=int(stack_len)-3 ; i>=0 ; --i)
|
|
||||||
if( IsNameEqual(pstack[i].name, pstack[stack_len-1].name) )
|
|
||||||
break;
|
|
||||||
|
|
||||||
if( i < 0 )
|
|
||||||
{
|
|
||||||
// oops, there is no such a tag
|
|
||||||
// we don't print the closing and the missing opening tag
|
|
||||||
PopStack();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
for(int z=(int)stack_len-2 ; z>=i ; --z)
|
|
||||||
{
|
|
||||||
CheckWhiteCharsExceptions(pstack[z]);
|
|
||||||
|
|
||||||
if( !skip_tags && pstack[z].new_line )
|
|
||||||
{
|
|
||||||
if( current_white_char_mode() == WHITE_MODE_TREE )
|
|
||||||
{
|
|
||||||
Put(10);
|
|
||||||
PutTabs(pstack[z].tree_index);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
PutClosingTag(pstack[z]);
|
|
||||||
pstack[z].Clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
//last_new_line = pstack[stack_len-1].new_line;
|
|
||||||
|
|
||||||
// invalidate tags
|
|
||||||
stack_len = i;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void HTMLParser::CheckStackPrintRest()
|
void HTMLParser::CheckStackPrintRest()
|
||||||
{
|
{
|
||||||
while( stack_len-- > 0 )
|
while( stack_len-- > 0 )
|
||||||
|
@ -1935,44 +1886,52 @@ void HTMLParser::CheckStackPrintRest()
|
||||||
|
|
||||||
void HTMLParser::CheckClosingTags()
|
void HTMLParser::CheckClosingTags()
|
||||||
{
|
{
|
||||||
|
int i;
|
||||||
|
|
||||||
if( stack_len == 0 )
|
if( stack_len == 0 )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// on the stack we have only opening tags
|
// on the stack we have only opening tags
|
||||||
// but only the last tag is a closing tag
|
// but only the last tag is a closing tag
|
||||||
|
|
||||||
if( stack_len == 1 )
|
if( stack_len < 3 )
|
||||||
{
|
{
|
||||||
// there is only last closing tag
|
|
||||||
// we dont print it
|
|
||||||
PopStack();
|
PopStack();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// there are more than one tag
|
// looking whether there is a matching opening tag
|
||||||
if( (pstack[stack_len-1].is_commentary && pstack[stack_len-2].is_commentary) || IsNameEqual(pstack[stack_len-1].name, pstack[stack_len-2].name) )
|
for(i=int(stack_len)-2 ; i >= 0 ; --i)
|
||||||
{
|
if( (pstack[i].is_commentary && pstack[stack_len-1].is_commentary) || IsNameEqual(pstack[i].name, pstack[stack_len-1].name) )
|
||||||
CheckWhiteCharsExceptions(pstack[stack_len-1]);
|
break;
|
||||||
|
|
||||||
// last closing tag is from the previous one
|
if( i < 0 )
|
||||||
if( !skip_tags && pstack[stack_len-2].new_line )
|
{
|
||||||
|
// oops, there is no such an opening tag on the stack
|
||||||
|
// we don't print the closing and the missing opening tag
|
||||||
|
PopStack();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
for(int z=(int)stack_len-2 ; z >= i ; --z)
|
||||||
|
{
|
||||||
|
CheckWhiteCharsExceptions(pstack[z]);
|
||||||
|
|
||||||
|
if( !skip_tags && pstack[z].new_line )
|
||||||
{
|
{
|
||||||
if( current_white_char_mode() == WHITE_MODE_TREE )
|
if( current_white_char_mode() == WHITE_MODE_TREE )
|
||||||
{
|
{
|
||||||
Put(10);
|
Put(10);
|
||||||
PutTabs(pstack[stack_len-2].tree_index);
|
PutTabs(pstack[z].tree_index);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
PutClosingTag(pstack[stack_len-1]);
|
PutClosingTag(pstack[z]);
|
||||||
//last_new_line = pstack[stack_len-1].new_line;
|
pstack[z].Clear();
|
||||||
PopStack();
|
|
||||||
PopStack();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
AddForgottenTags();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// invalidate items on the stack
|
||||||
|
stack_len = i;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue