Merge pull request #398 from rtack/issue-396

allow zero LI in UL when html5. fix for #396
This commit is contained in:
Geoff McLane 2016-04-16 20:14:22 +02:00
commit 0ab4c48711
4 changed files with 20 additions and 5 deletions

View file

@ -328,7 +328,6 @@ static Bool CanPrune( TidyDocImpl* doc, Node *element )
if (nodeIsDD(element)) if (nodeIsDD(element))
return no; return no;
return yes; return yes;
} }
@ -2514,7 +2513,14 @@ void TY_(ParseList)(TidyDocImpl* doc, Node *list, GetTokenMode ARG_UNUSED(mode))
continue; continue;
} }
if ( !nodeIsLI(node) ) if ( nodeIsLI(node) || TY_(IsHTML5Mode)(doc))
{
/* node is <LI>
Issue #396 - A <ul> can have Zero or more li elements
*/
TY_(InsertNodeAtEnd)(list,node);
}
else
{ {
TY_(UngetToken)( doc ); TY_(UngetToken)( doc );
@ -2567,9 +2573,6 @@ void TY_(ParseList)(TidyDocImpl* doc, Node *list, GetTokenMode ARG_UNUSED(mode))
TY_(InsertNodeAtEnd)(list,node); TY_(InsertNodeAtEnd)(list,node);
} }
} }
else
/* node is <LI> */
TY_(InsertNodeAtEnd)(list,node);
ParseTag( doc, node, IgnoreWhitespace); ParseTag( doc, node, IgnoreWhitespace);
} }

View file

@ -780,6 +780,12 @@ void TY_(AdjustTags)( TidyDocImpl *doc )
} }
} }
Bool TY_(IsHTML5Mode)( TidyDocImpl *doc )
{
return doc->HTML5Mode;
}
/*\ /*\
* Issue #285 * Issue #285
* Reset the table to default HTML5 mode. * Reset the table to default HTML5 mode.
@ -809,6 +815,7 @@ void TY_(ResetTags)( TidyDocImpl *doc )
#if ELEMENT_HASH_LOOKUP #if ELEMENT_HASH_LOOKUP
tagsEmptyHash( doc, tags ); /* not sure this is really required, but to be sure */ tagsEmptyHash( doc, tags ); /* not sure this is really required, but to be sure */
#endif #endif
doc->HTML5Mode = yes; /* set HTML5 mode */
} }
void TY_(FreeTags)( TidyDocImpl* doc ) void TY_(FreeTags)( TidyDocImpl* doc )
@ -823,6 +830,8 @@ void TY_(FreeTags)( TidyDocImpl* doc )
/* get rid of dangling tag references */ /* get rid of dangling tag references */
TidyClearMemory( tags, sizeof(TidyTagImpl) ); TidyClearMemory( tags, sizeof(TidyTagImpl) );
doc->HTML5Mode = no; /* reset html5 mode == legacy html4 mode */
} }

View file

@ -88,6 +88,7 @@ void TY_(InitTags)( TidyDocImpl* doc );
void TY_(FreeTags)( TidyDocImpl* doc ); void TY_(FreeTags)( TidyDocImpl* doc );
void TY_(AdjustTags)( TidyDocImpl *doc ); /* if NOT HTML5 DOCTYPE, fall back to HTML4 legacy mode */ void TY_(AdjustTags)( TidyDocImpl *doc ); /* if NOT HTML5 DOCTYPE, fall back to HTML4 legacy mode */
void TY_(ResetTags)( TidyDocImpl *doc ); /* set table to HTML5 mode */ void TY_(ResetTags)( TidyDocImpl *doc ); /* set table to HTML5 mode */
Bool TY_(IsHTML5Mode)( TidyDocImpl *doc );
/* Parser methods for tags */ /* Parser methods for tags */

View file

@ -76,6 +76,8 @@ struct _TidyDocImpl
uint badChars; /* for bad char encodings */ uint badChars; /* for bad char encodings */
uint badForm; /* bit field, for badly placed form tags, or other format errors */ uint badForm; /* bit field, for badly placed form tags, or other format errors */
Bool HTML5Mode; /* current mode is html5 */
/* Memory allocator */ /* Memory allocator */
TidyAllocator* allocator; TidyAllocator* allocator;