Skip to content

Unexpected warning "plain text isn't allowed in head elements" under --show-body-only yes #314

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

Closed
benkasminbullock opened this issue Nov 22, 2015 · 4 comments
Labels
Milestone

Comments

@benkasminbullock
Copy link
Contributor

Given the following HTML,

fruit cakes
<p>Christmas cakes</p>

the command

./tidy --show-body-only yes --quiet yes ~/goo.html 

produces output

line 2 column 1 - Warning: plain text isn't allowed in <head> elements
line 2 column 1 - Info: <head> previously mentioned
fruit cakes
<p>Christmas cakes</p>

The initial warning seems very odd to me. Adding a body tag makes no difference and also generates another error:

fruit cakes
<body>
<p>Christmas cakes</p>
</body>

gives

line 2 column 1 - Warning: plain text isn't allowed in <head> elements
line 2 column 1 - Info: <head> previously mentioned
line 3 column 1 - Warning: discarding unexpected <body>
fruit cakes
<p>Christmas cakes</p>
@geoffmcl
Copy link
Contributor

@benkasminbullock agree warnings do look a little odd.

If --show-body-only yes we already suppress some other head messages. Maybe these two could likewise be suppressed?

PR or patch welcome.

@geoffmcl
Copy link
Contributor

@benkasminbullock looked into this... as suggested, seems can suppress that warning with a simple condition expansion, using the services of showingBodyOnly macro, presently only available in parser.c, but could be expanded... so the patch is -

diff --git a/src/parser.c b/src/parser.c
index 6924828..e751130 100644
--- a/src/parser.c
+++ b/src/parser.c
@@ -3639,8 +3639,9 @@ void TY_(ParseHead)(TidyDocImpl* doc, Node *head, GetTokenMode ARG_UNUSED(mode))
         {
             /*\ Issue #132 - avoid warning for missing body tag,
              *  if configured to --omit-otpional-tags yes
+             *  Issue #314 - and if --show-body-only
             \*/
-            if (!cfgBool( doc, TidyOmitOptionalTags )) {
+            if (!cfgBool( doc, TidyOmitOptionalTags ) && !showingBodyOnly(doc) ) {
                 TY_(ReportError)(doc, head, node, TAG_NOT_ALLOWED_IN);
             }
             TY_(UngetToken)( doc );

I am presently testing in the issue-329 branch so have added that patch there... to be later merged to master, or at least cherry-picked into master, if the testing fails on this branch...

If you could get a chance to update, and pull that issue-329 branch, and confirm the message is absent when the option --show-body-only yes is set... that would be great... thanks...

@geoffmcl
Copy link
Contributor

@benkasminbullock sorry for the delay. This issue got mixed with #329 and almost lost!

It is now in master branch, version 5.1.43 onwards...

Concerning your 2nd issue, when adding a <body> after bare text, I have decided to do nothing about this at this time.

On finding bare text, tidy has to insert an implicit <body>, as a container to hold this text, so will still report line 2 column 1 - Warning: discarding unexpected <body>.

Yes this could be more verbose like discarded unexpected <body> because have already inserted an implicit <body> on finding bare text., but maybe this would be excessive? Hope you agree.

Appreciated if you could pull and build, and if satisfactory close this issue... thanks...

@geoffmcl
Copy link
Contributor

@benkasminbullock, since there are no further comments in over 3 weeks, assume this is closed...

Please feel free to re-open or post a new issue. Tidy needs your help! thanks...

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

2 participants