Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No way to get past complaints about <style> outside of <head> #730

Open
petdance opened this issue May 11, 2018 · 2 comments
Open

No way to get past complaints about <style> outside of <head> #730

petdance opened this issue May 11, 2018 · 2 comments
Labels
Milestone

Comments

@petdance
Copy link
Contributor

Here's an HTML file with <style> tag outside of the <head>.

$ cat -n foo.html
     1  <!DOCTYPE html>
     2  <html>
     3      <head>
     4          <title> style outside of the head </title>
     5      </head>
     6      <body>
     7          <style>
     8              foo { text-align: center }
     9          </style>
    10          <p class="foo">
    11              This should be centered
    12          </p>
    13      </body>
    14  </html>

Tidy complains about it.

$ tidy -q -e foo.html
line 7 column 9 - Warning: moved <style> tag to <head>! fix-style-tags: no to avoid.

So I do what tidy says and it complains a different complaint.

$ tidy -q -e --fix-style-tags no foo.html
line 7 column 9 - Warning: found <style> tag in <body>! fix-style-tags: yes to move.

What can I do to make tidy happy about this situation?

@petdance petdance added the Bug label May 11, 2018
@geoffmcl
Copy link
Contributor

@petdance yes, I think this is a bug, and needs to be fixed

This seems yet another case where tidy needs to support the current HTML5 spec...

I can read in style docs <style> can be used In the body, where flow content is expected.... although there are some warning type notes about it...

One quick patch I experimented with was -

diff --git a/src/clean.c b/src/clean.c
index e96dd3f..8023616 100644
--- a/src/clean.c
+++ b/src/clean.c
@@ -2747,7 +2747,7 @@ static void StyleToHead(TidyDocImpl* doc, Node *head, Node *node, Bool fix, int
 				TY_(InsertNodeAtEnd)(head, node);   /* add to end of head */
 				TY_(Report)(doc, node, head, MOVED_STYLE_TO_HEAD); /* report move */
 			}
-			else
+			else if (!TY_(IsHTML5Mode)(doc)) /* Is. #730 - style allowed in body */
 			{
 				TY_(Report)(doc, node, head, FOUND_STYLE_IN_BODY);
 			}

But maybe this is not the complete story... because this would allow it to be the child of anything... maybe there needs to be more checking... although, with --fix-style-tags no it does fix the sample given...

Note such a fix may also mean adjusting, changing the fix-style-tags documentation, or its yes default, and/or the MOVED_STYLE_TO_HEAD and the FOUND_STYLE_IN_BODY messages...

Look forward to feedback, patches, or PR... thanks...

@petdance
Copy link
Contributor Author

I don't have any feedback one way or the other. I would just expect that if you turn on one flag, it wouldn't suggest you turn on a different one.

@balthisar balthisar added this to the 5.9 milestone Jul 9, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants