Re: Some comments on HTML tidy

Bjoern Hoehrmann <[email protected]> Sat, 31 Dec 2005 21:02:00 +0100
Newsgroups gmane.comp.web.html-tidy.devel
Message-ID <[email protected]>
* Reece Dunn wrote:
>I am using HTML tidy as a HTML parser that feeds into a text outputter to do 
>HTML ==> text conversion. This is a great tool, but here are a few things I 
>have noticed and have modified:
>
>[1]  in the C++ binding (tidyx.h), IsHeader() is missing a return statement:
>-    Bool IsHeader()      { tidyNodeIsHeader( tnod() ); } /* h1, h2, ... */
>+    Bool IsHeader()      { return tidyNodeIsHeader( tnod() ); } /* h1, h2, 
>... */
>
>[2]  the C++ binding functions should be const qualified, e.g.
>
>    Bool IsHTML() const       { return tidyNodeIsHTML( tnod() ); }

(There are several C++ bindings and they are not part of the sf.net
projects, if the author does not read this list, I would suggest to
send the feedback directly to the author).

>[4]  normally, any extended character (e.g. &emdash;) is outputted in its 
>escaped form when you specify an output encoding. For my application, I want 
>to prevent the escaping of these characters. As such, I have added a 
>TidyNoCharEscaping option to disable character escaping.

The default output encoding is US-ASCII so Tidy has to escape those;
if you specify UTF-8 as output encoding, Tidy won't use character
references for characters other than &'"<> and maybe U+00A0.

>[5] HTML tidy doesn't appear to have any auto detection of the character 
>encoding being used (except for the UTF BOM). That is, any <meta> tag that 
>specifies the text encoding. Is there an easy way that I can do this?

Well, you would have to assume some character encoding, parse the
document until you find a <meta>, if that's a different encoding go
back to step 1 assuming the specified character encoding and parse the
document again, this time without looking for <meta>. You would need
additional logic for <?xml?>-style encoding declarations. There is a
little bit of code for this, but adding it to Tidy would require some
work still. Patches very much appreciated, you might want to have a look
at my HTML::Encoding Perl module on CPAN.

>[6] I am having problems getting the <win32tc.h> logic 
>(TIDY_WIN32_MLANG_SUPPORT) working. It is producing an access violation that 
>I have not (yet) been able to track down - it appears to be happening 
>somewhere in ole32.dll.

This is highly experimental and there might be problems compiling this
as C++ (just guessing, it uses the C-ish way for COM stuff in any case).
That said, when I looked at the code last time, it worked for me.
-- 
Björn Höhrmann · mailto:[email protected] · http://bjoern.hoehrmann.de
Weinh. Str. 22 · Telefon: +49(0)621/4309674 · http://www.bjoernsworld.de
68309 Mannheim · PGP Pub. KeyID: 0xA4357E78 · http://www.websitedev.de/ 


-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
for problems?  Stop!  Download the new AJAX search engine that makes
searching your log files as easy as surfing the  web.  DOWNLOAD SPLUNK!
http://ads.osdn.com/?ad_id=7637&alloc_id=16865&op=click