W3C home > Mailing lists > Public > html-tidy@w3.org > July to September 2006

Re: tidy shouldn't parse a php file text/css

From: Lindsay Haisley <fmouse@fmp.com>
Date: Tue, 11 Jul 2006 13:33:05 -0500
To: Enzo <jdespatis@yahoo.fr>
Cc: html-tidy@w3.org
Message-ID: <20060711183305.GA1695@fmp.com>

Thus spake Enzo on Tue, Jul 11, 2006 at 04:19:39AM CDT
> Hi
> I've installed Tidy, i have in my apache config:
> AddOutputFilterByType   TIDY    text/html
> So it should process only text/html files, however i have a simple php script 
> that does this:
> <?php
>   header("Content-Type: text/css");
>   echo "some css...";
> ?>
> And this file is also processed by tidy, but it shouldn't
> Any idea how i can fix that ?
> Every trick is welcome (force type on certain files, force tidy not to 
> execute on certain files, etc...)
> I've tried many things, i don't find...  Maybe someone of you has a work 
> around

The way I use tidy is as an external "program" in my HTML editor (Bluefish).  
The script (/usr/local/bin/newtidy) is an executable PHP CLI-mode script.  
Here's my script:


function doc($errno=0, $errordsc="") {
        global $argv;
        if ($errordsc) {
                printf("Error: %u  -  %s\n\n", $errno, $errordsc);
        printf("Usage: %s [-e] [-c <config_file>] [-h] infile\n", $argv[0]);
        printf("       -e - Show errors (as HTML comment block)\n");
        printf("       -c - use <config_file> for config instead of /etc/newtidy/newtidy.conf\n");
        printf("       -h - show this help\n");
        if ($errordsc) exit(1);
        else exit(0);
if($argc == 1) doc();
if (isset($options["h"])) doc();
if (isset($options["c"]) && $options["c"]) $config_file = $options["c"];
else $config_file = "/etc/newtidy/newtidy.conf";

$fh = fopen($argv[$argc - 1], "r");
$html = fread($fh, filesize($argv[$argc - 1]));
$tidy = tidy_parse_string($html, $config_file, "utf8");
echo $tidy;
if (isset($options["e"])) {
        echo "\n<!--\n";
        printf("Error count:   %u\n", tidy_error_count($tidy));
	printf("Warning count: %u\n", tidy_warning_count($tidy));
        echo $tidy->errorBuffer;
        echo "-->\n";

There's a bunch of extraneous self-doc stuff in here, which I generally put in 
my scripts, but the point is that you have all the flexibility you need.  You 
could, for instance, parse the name of $argv[$argc - 1] and if it ends in 
".css" or ".php"  you could bypass the calls to the tidy cleanRepair method and 
other calls to tidy related functions.

This assumes that you've installed CLI-mode PHP and built it with support for 

I didn't care for the fact that I had to, in effect, write my own tidy program, 
but once I found out how simple it is to work with PHP's tidy object I found 
that I really like the flexibility it gives me.  You can see, for instance, 
that if my script is invoked with "-e", the resulting output contains a listing 
of errors and warnings from tidy enclosed in HTML comments.

Lindsay Haisley       | "Fighting against human |     PGP public key
FMP Computer Services |    creativity is like   |      available at
512-259-1190          |    trying to eradicate  | <http://pubkeys.fmp.com>
http://www.fmp.com    |        dandelions"      |
                      |      (Pamela Jones)     |
Received on Tuesday, 11 July 2006 20:30:13 UTC

This archive was generated by hypermail 2.3.1 : Tuesday, 6 January 2015 21:38:56 UTC