Sean Allen wrote:
> anyone done anything about getting html tidy to play nice with  
> template toolkit syntax?
>
> don't want to redo what is already done, google isn't helping then again
>
> template toolkit tidy html
>
> in any combo bring up a ton of stuff isn't relevant so maybe its out  
> there just lost in the noise.
>   
If I understand your question right I've been doing something like this 
in an application of mine:

sub tidy_html_string {
  my $content=shift @_;

  use Regexp::Common qw( balanced );
  use MIME::Base64 ();
  use Encode ();
  use HTML::Tidy ();

  my $tidy=HTML::Tidy->new();

  # Obfuscate TT markup
  # MIME::Base64 must be done on bytes, not perl character strings
  $content=~s/$RE{balanced}{-begin => "[%"}{-end => "%]"}{-keep}/'tt_begin:'
    . MIME::Base64::encode($1,'')
    . ':tt_end'/ge;

  # HTML::Tidy wants to work on perl character data
  $content=Encode::decode_utf8($content);
  $content=$tidy->clean($content);
  $content=Encode::encode_utf8($content);

  # Get back obfuscated TT markup
  $content=~s/$RE{balanced}{-begin => "tt_begin:"}{-end => 
":tt_end"}{-keep}/
    my $var=$1;
    my $len=length($var);
    MIME::Base64::decode(substr($var, 9, $len-16 ));
  /ge if $content;

  return $content;

}

If your input string is not binary UTF-8 text, some twiddling with the 
encode/decode functions will be needed. Just remember that MIME::Base64 
works on bytes, but HTML::Tidy likes to work on perl character strings.

If your input is plain 7-bit ASCII the encoding/decoding is a non-issue 
and can be ignored.

Regards,
 Robin Smidsrød

 

_______________________________________________
templates mailing list
[email protected]
http://mail.template-toolkit.org/mailman/listinfo/templates

Reply via email to