Skip to content

Commit d4ca02a

Browse files
committed
Issue #567 - Branch 'issue-567-2' to move all 'style' to 'head'
1 parent e48b06b commit d4ca02a

File tree

3 files changed

+57
-0
lines changed

3 files changed

+57
-0
lines changed

src/clean.c

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2647,6 +2647,58 @@ void TY_(FixAnchors)(TidyDocImpl* doc, Node *node, Bool wantName, Bool wantId)
26472647
}
26482648
}
26492649

2650+
/* Issue #567 - move style elements from body to head */
2651+
void TY_(CleanStyle)(TidyDocImpl* doc, Node *html)
2652+
{
2653+
Node *node, *next, *head = NULL, *body = NULL;
2654+
Node *child;
2655+
if (!html)
2656+
return; /* oops, not given a start node */
2657+
2658+
#if 0 /* this failed??? */
2659+
for (node = html->content; node != NULL; node = node->next)
2660+
{
2661+
if (nodeIsHEAD(node))
2662+
head = node;
2663+
2664+
if (nodeIsBODY(node))
2665+
body = node;
2666+
}
2667+
#endif /* 0000000000000000000000 */
2668+
head = TY_(FindHEAD)( doc );
2669+
body = TY_(FindBody)( doc );
2670+
2671+
if (head != NULL && body != NULL)
2672+
{
2673+
/* found head and body */
2674+
for (node = body->content; node != NULL; node = next)
2675+
{
2676+
next = node->next;
2677+
if (nodeIsSTYLE(node))
2678+
{
2679+
TY_(RemoveNode)(node); /* unhool style node from body */
2680+
TY_(InsertNodeAtEnd)(head, node); /* add to end of head */
2681+
/* TODO: Add warning */
2682+
}
2683+
else if (node->content)
2684+
{
2685+
for (child = node->content; child != NULL; child = child->content)
2686+
{
2687+
if (nodeIsSTYLE(child))
2688+
{
2689+
TY_(RemoveNode)(child); /* unhool style node from body */
2690+
TY_(InsertNodeAtEnd)(head, child); /* add to end of head */
2691+
/* TODO: Add warning */
2692+
break;
2693+
}
2694+
2695+
}
2696+
2697+
}
2698+
}
2699+
}
2700+
}
2701+
26502702
/*
26512703
* local variables:
26522704
* mode: c

src/clean.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,5 +78,7 @@ void TY_(FixAnchors)(TidyDocImpl* doc, Node *node, Bool wantName, Bool wantId);
7878
void TY_(FixXhtmlNamespace)(TidyDocImpl* doc, Bool wantXmlns);
7979
void TY_(FixLanguageInformation)(TidyDocImpl* doc, Node* node, Bool wantXmlLang, Bool wantLang);
8080

81+
/* Issue #567 - move style elements from body to head */
82+
void TY_(CleanStyle)(TidyDocImpl* doc, Node *html);
8183

8284
#endif /* __CLEAN_H__ */

src/tidylib.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2011,6 +2011,9 @@ int tidyDocCleanAndRepair( TidyDocImpl* doc )
20112011
if (tidyXmlTags)
20122012
return tidyDocStatus( doc );
20132013

2014+
/* Issue #567 - move style elements from body to head */
2015+
TY_(CleanStyle)(doc, &doc->root);
2016+
20142017
/* simplifies <b><b> ... </b> ...</b> etc. */
20152018
if ( mergeEmphasis )
20162019
TY_(NestedEmphasis)( doc, &doc->root );

0 commit comments

Comments
 (0)