Skip to content

Commit d4a11b5

Browse files
authored
Merge pull request #577 from htacg/issue-572
Issue 572
2 parents a26c4e0 + 09f1806 commit d4a11b5

File tree

1 file changed

+26
-3
lines changed

1 file changed

+26
-3
lines changed

src/parser.c

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2435,6 +2435,7 @@ void TY_(ParseList)(TidyDocImpl* doc, Node *list, GetTokenMode ARG_UNUSED(mode))
24352435
Lexer* lexer = doc->lexer;
24362436
Node *node, *parent, *lastli;
24372437
Bool wasblock;
2438+
Bool nodeisOL = nodeIsOL(list);
24382439

24392440
#if !defined(NDEBUG) && defined(_MSC_VER)
24402441
in_parse_list++;
@@ -2452,6 +2453,7 @@ void TY_(ParseList)(TidyDocImpl* doc, Node *list, GetTokenMode ARG_UNUSED(mode))
24522453

24532454
while ((node = TY_(GetToken)( doc, IgnoreWhitespace)) != NULL)
24542455
{
2456+
Bool foundLI = no;
24552457
if (node->tag == list->tag && node->type == EndTag)
24562458
{
24572459
TY_(FreeNode)( doc, node);
@@ -2473,6 +2475,21 @@ void TY_(ParseList)(TidyDocImpl* doc, Node *list, GetTokenMode ARG_UNUSED(mode))
24732475
TY_(FreeNode)( doc, node);
24742476
continue;
24752477
}
2478+
if (lexer && (node->type == TextNode))
2479+
{
2480+
uint ch, ix = node->start;
2481+
/* Issue #572 - Skip whitespace. */
2482+
while (ix < node->end && (ch = (lexer->lexbuf[ix] & 0xff))
2483+
&& (ch == ' ' || ch == '\t' || ch == '\r' || ch == '\n'))
2484+
++ix;
2485+
if (ix >= node->end)
2486+
{
2487+
/* Issue #572 - Discard if ALL whitespace. */
2488+
TY_(FreeNode)(doc, node);
2489+
continue;
2490+
}
2491+
}
2492+
24762493

24772494
/*
24782495
if this is the end tag for an ancestor element
@@ -2521,10 +2538,16 @@ void TY_(ParseList)(TidyDocImpl* doc, Node *list, GetTokenMode ARG_UNUSED(mode))
25212538
continue;
25222539
}
25232540

2524-
if ( nodeIsLI(node) || TY_(IsHTML5Mode)(doc))
2541+
if ( !nodeIsLI(node) && nodeisOL )
2542+
{
2543+
/* Issue #572 - A <ol><li> can have nested <ol> elements */
2544+
foundLI = FindLastLI(list, &lastli); /* find last <li> */
2545+
}
2546+
2547+
if ( nodeIsLI(node) || (TY_(IsHTML5Mode)(doc) && !foundLI) )
25252548
{
2526-
/* node is <LI>
2527-
Issue #396 - A <ul> can have Zero or more li elements
2549+
/* node is <LI> OR
2550+
Issue #396 - A <ul> can have Zero or more <li> elements
25282551
*/
25292552
TY_(InsertNodeAtEnd)(list,node);
25302553
}

0 commit comments

Comments
 (0)