Re: [htmltmpl] Stripping blank lines caused by TMPL tags
Brought to you by:
samtregar
From: Mitar <mm...@gm...> - 2005-09-28 18:36:54
|
Hi! > This gets me the results I was looking for but feel that it is very much = a > kludge. Have I missed something in the docs like a param for the > constructor that automagicly does the same thing I have done minus me hav= ing > to do anything? Having seen the results of an HTML::Template minus the > blank lines makes me want to see such results all the time without modify= ing > my code and templates to do so. I use this filter: our $line_merger =3D sub { =09my $text_ref =3D shift; =09# Removes HTML comment style format from the tags (so that next regex wo= rks) =09$$text_ref =3D~ s/<!--\s*(~?\/?TMPL_.+?)\s*-->/<$1>/gis; =09# "Cleans" tags in such a way that it removes the space characters and ~ (so if there is no ~ it does not =09# remove anything) =09$$text_ref =3D~ s/(?:\n[ \t]*(?=3D<~))?<~?(\/?TMPL_[^>~]+)~?(\/?)>(?:(?:(?<=3D~\/>)|(?<=3D~>))[ \t]*\n)?/<$1$2>/gis; }; The idea is that I can use ~ character to specify that I want newline remov= ed. For example: <~TMPL_VAR NAME=3D"foo"~> will remove newline before and after the tag (if there is any). In most cases I use only second ~ as this efficiently (in most template uses) removes all newlines after the tags and so there are no empty lines in the output. Mitar |