diff --git a/src/clean.c b/src/clean.c index e96dd3f..61c9596 100644 --- a/src/clean.c +++ b/src/clean.c @@ -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 diff --git a/src/clean.h b/src/clean.h index f0ef7a6..c765e81 100644 --- a/src/clean.h +++ b/src/clean.h @@ -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__ */ diff --git a/src/tidylib.c b/src/tidylib.c index 67d7a37..7396c74 100644 --- a/src/tidylib.c +++ b/src/tidylib.c @@ -2153,6 +2153,8 @@ int tidyDocCleanAndRepair( TidyDocImpl* doc ) } } + TY_(CleanHead)(doc); /* Is #692 - discard multiple tags */ + #if defined(ENABLE_DEBUG_LOG) SPRTF("All nodes AFTER clean and repair\n"); dbg_show_all_nodes( doc, &doc->root, 0 );