Closed justinhartman closed 6 years ago
@justinhartman thank you for the issue...
I'm very confused how the file below can create this perception that the content is
html5
content.
Well do not be confused! You created
this by passing the file to tidy
. Tidy
treats every and any file passed to it as html
, or xhtml
, and looks at the content as that markup type code... will try to fix it if it can, and report warnings and errors...
And if tidy
does not find a DOCTYPE
it will assume html5
...
Now it seems you passed an unclosed processing instruction block, <?php ...
, so tidy just threw that away. If you had added the close
it was looking for ... ?>
, it would have kept it as part of the html document... Try the following php
and you should see what I mean -
<?php
function foo()
{
return 1;
} // end foo()
?>
But as I am sure you know, in a xhtml
document, such processing instruction
are usually within the document body, like -
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>#782-3</title>
</head>
<body>
<?php
function foo()
{
return 1;
} // end foo()
?>
</body>
</html>
That file will pass tidy
with no errors or warnings, as with the W3C validator...
So far I can not see any tidy
bug here, except maybe, but only maybe, it could report something like an line 1 column 1 - Warning: unclosed processing block discarded
on the above php
sample, but that should be a separate issue. If someone was interested enough to look into this and raise an issue, that would be appreciated, and dealt with separately...
Now I know nothing about SublimeLinter
, or Sublime Text
editor, but it seems you should explore the multiple options for tidy
- see QuickRef.html
But this is only if you are passing a [x]html
document to tidy
. Certainly not a pure php
file, that is with no html
markup...
For example, if you have no interest in the head
part of the html
, then --show-body-only yes
might be what you need... That does avoid some head
warnings...
If you do not want to see specific warnings
, then discover their ID
with --mute-id yes
, and then supply a --mute <ID>
option, one for each message you want to suppress...
Or even --show-warnings no
to even suppress all warnings, show only errors
, if any. And/or --show-info no
... And/or --quiet yes
...
Have not explored all the options available, but it seems there should be one or more to get the tidy
ouput you want...
Does this answer your question, or have I missed something? Thanks...
@geoffmcl thank you so much for (a) your detailed response and (b) being so diligent in helping me understand the underlying issue with this issue report. I completely get what you are saying here and can now see the error of my ways 😄
The main issue is that SublimeLinter
executes all installed linters on a file, irrespective of file-type, file structure, etc. This effectively means that no matter what, when applying the lint
function in Sublime
using SublimeLinter
it will process all installed linters available and in turn, each linter will return a set of results, and in this case errors.
Now it seems you passed an unclosed processing instruction block, <?php ..., so tidy just threw that away. If you had added the close it was looking for ... ?>, it would have kept it as part of the html document... Try the following php and you should see what I mean.
Yes, running your example gave me the expected results and once my PHP codeblock was closed off the errors were omitted from the block itself and phpcs
took over.
I don't know if SublimeLinter
has the ability to turn off certain linters based on the file-type or code-block being checked but what is clear is that this is not an issue with tidy-html5
but rather an issue with either Sublime
or SublimeLinter
.
Thank you for your patience and detailed response to an issue that clearly wasn't an issue with tidy-html5
. I appreciate it immensely and thank you for your time.
I am satisfied that this isn't an issue that should remain open so please feel free to close this without response.
Regards, Justin
@geoffmcl I do want to ask one question though. When I run $ tidy original-index.php -o index.md --show-warnings false
why is it that tidy
still shows me warning messages (irrespective that the file is pure PHP) when this flag is set? Surely the expected result is that tidy
will only output errors
and not warnings
?
@justinhartman glad to hear you seem to have found your problem... do not pass pure php
only files to tidy
... it will treat them as html markup code...
The command $ tidy original-index.php -o index.md --show-warnings false
may be a problem. If the intended input file is original-index.php
, then it seems to be in the WRONG order...
From the API docs you can see the command is tidy [[options] filename]
Note the input html filename comes last
, and if none given tidy
will read stdin
...
The reading of stdin
allows for $ echo "Hello World" | tidy -q --show-warnings no
usage... try it...
Change that to $ tidy -o index.md --show-warnings false original-index.php
, and you should get what you want...
And note that in fact you can have multiple input
files, and multiple sets of options
, like -
$ tidy [options1] [file1 [file2 ...] [options2] [file3...]]
This will process file1 ...
with the first set of options1
, then file3
with added options2
, and so on...
Now in your case you have given $ tidy file1 options
, which means tidy
will process file1
, then read the options
, then use stdin
for the final input file...
HTH...
Anyway, glad you closed this... thanks...
I am experiencing a similar problem with the "Inserting missing 'title' element" feature. I have files that are included in other files. Obviously those include files should not be passed to tidy, but I'm passing hundreds of files to tidy via a batch file and it's challenging to exclude a list of specific (and changing) files.
It seems like there should be a way to say, "Don't insert a missing doctype or title. If they're missing, just treat it as an error, and don't modify the file."
@Sachelis this issue was closed, over a year ago, and your new comment here seems to be different, an entirely different request...
It seems you want an option, to sort of say, don't be tidy, or something... ;=))
i.e. Don't insert a missing doctype or title... don't modify the file.
! WOW really...
Why would you want that? What do you want tidy to do? Why are you passing this file to tidy
in the first place... what gain are you looking for?
If you just want the body html, have you tried --show-body-only yes
- API...
But other than that, to ignore missing doctype or title
seems nearly impossible...
I just do not see a use
case for that...but if you think you can build one, please open a new issue, with full explanation and reasoning... thanks
Meantime, this issue remains CLOSED... thanks...
Hi guys,
I'm having a problem with
tidy
in that it keeps showing me the warninginserting missing 'title' element
on php-only files. There is no way for me to ignore this warning and it's bugging the living hell out of me. I'm usingtidy
along with two plugins forSublime Text 3
and getting this warning both usingtidy
directly from the command line as well as in the console output ofSublime
.This is my environment.
Hardware
Software
I installed
tidy
directly viahomebrew
:Settings
This is my configuration file for SublimeLinter in Sublime text editor:
I am using SublimeLinter-html-tidy as the plugin that ties
tidy
in to theSublime
user space so that I can linthtml
documents. In the aboveSublimeLinter
settings I am usingignore_match
to exclude theinserting missing 'title' element
warning from appearing in thehtmltidy
,php
andphpcs
linter plugins.SublimeLinter-html-tidy
or rathertidy
itself, is not respecting this setting and continues to output the warning. I don't needtidy
to do this for me, I havephpcs
installed to deal with linting ofphp
files.But, as this is a bug report about
tidy
and notSublime
or its plugins, the following is my$ tidy -show-config
Configuration File Settings output from the terminal:PHP Sample
For your reference, here is my full
php
file so that you can see there is no hint ofhtml
in it. I am including the full file (instead of a sample) because when you see the outputs later on in this ticket you will notice the references tohtml5
and themissing title element
but I'm very confused how the file below can create this perception that the content ishtml5
content.Errors when running tidy
I created the above
php
only file with zerohtml
in it so there is no possible way I can add atitle
element. There is clearly a bug here in that it cannot determine that nor can it ignore the overide setting.SublimeLinter output
Here is the warning I am receiving when linting my
php
file:Terminal output running
tidy
directlyThis is what happens when I run
$ tidy original-index.php -o index.md
against myoriginal-index.php
file:What confuses me a lot is that
tidy
is giving me an information notice thatDocument content looks like HTML5
and this makes me wonder how this is related to theinserting missing 'title' element
thattidy
keeps warning me about. There should be no reason for it to pick up the doc content ashtml5
. Nothing, and I mean nothing, even remotely looks likehtml5
in the PHP file.Setting
--show-warnings
flag tofalse
If I try and change the
--show-warnings
flag tofalse
in bothtidy
command line and in theSublimeLinter
settings file I still get the warning output. It doesn't respect the--show-warnings
flag either.So, is this a bug that needs fixing or is this me missing something completely?