Is #692 - Add a 'CleanHead' service

This commit is contained in:
Geoff McLane 2018-03-27 15:36:15 +02:00
parent 3843cdc3aa
commit 8d5ff2c514
3 changed files with 36 additions and 0 deletions

View File

@ -2780,6 +2780,37 @@ void TY_(CleanStyle)(TidyDocImpl* doc, Node *html)
/* ==================================================
*/
/*
* CleanHead - clean the head node, if it exists, and we
* are going to show it in the output.
* Issue #692 - Remove multiple title elements
*/
void TY_(CleanHead)(TidyDocImpl* doc)
{
Node *head, *node, *next;
uint titles = 0;
if (cfgAutoBool(doc, TidyBodyOnly) == TidyYesState)
return; /* not going to show head, so forget it */
head = TY_(FindHEAD)(doc);
if (!head)
return;
node = head->content;
while (node)
{
next = node->next; /* get any 'next' */
if (nodeIsTITLE(node))
{
titles++;
if (titles > 1)
{
TY_(Report)(doc, head, node, DISCARDING_UNEXPECTED);
TY_(DiscardElement)(doc, node); /* delete this node */
}
}
node = next;
}
}
/*
* local variables:
* mode: c

View File

@ -75,5 +75,8 @@ void TY_(FixLanguageInformation)(TidyDocImpl* doc, Node* node, Bool wantXmlLang,
/* Issue #567 - move style elements from body to head */
void TY_(CleanStyle)(TidyDocImpl* doc, Node *html);
/* Issue #692 - discard multiple titles */
void TY_(CleanHead)(TidyDocImpl* doc);
#endif /* __CLEAN_H__ */

View File

@ -2153,6 +2153,8 @@ int tidyDocCleanAndRepair( TidyDocImpl* doc )
}
}
TY_(CleanHead)(doc); /* Is #692 - discard multiple <title> tags */
#if defined(ENABLE_DEBUG_LOG)
SPRTF("All nodes AFTER clean and repair\n");
dbg_show_all_nodes( doc, &doc->root, 0 );