Skip Menu |
 

This queue is for tickets about the HTML-Tree CPAN distribution.

Report information
The Basics
Id: 33961
Status: open
Priority: 0/
Queue: HTML-Tree

People
Owner: Jeff.Fearn [...] gmail.com
Requestors: colin.fine [...] pace.co.uk
Cc:
AdminCc:

Bug Information
Severity: Wishlist
Broken in: 3.23
Fixed in: (no value)



Subject: Allow optional_end_tags to be set globally
Download (untitled) / with headers
text/plain 1.4k
I've just spent a couple of hours trying to isolate what I thought was a bug in HTML::Element (which I use for generating HTML, not for parsing it). The code was effectively: new HTML::Element('div')->push_content( ['p', 'para 1'], new HTML::Element('input', type => 'text', id => 'fred'), )->as_HTML; To me this is pretty clearly specifying a 'p' followed by an 'input' - if I had wanted the 'input' to be included in the 'p', I would have put it inside the []. So I could not understand why the 'input' was included in the 'p'. Even when I tried not using lol notation, and wrote new HTML::Element('p')->push_content('para 1'), new HTML::Element('input', ... the same happened. Eventually I read the documentation of as_HTML more carefully, and saw that by default it not only creates code that is broken if I happen to have an XHTML DOCTYPE, but also converts the perfectly clear structure I had above into something different - because it omits the closing tag on 'p'. I cannot imagine why anybody would want to *generate* HTML without closing tags (it's different writing it yourself) but I appreciate that you must not change existing behaviour. But PLEASE can you provide a configuration so that I can say at the start of my program something like $HTML::Element::optional_end_tags = {}; or $HTML::dont_break_my_code = 1; and not have to tell every call to as_HTML not to break my structure. Thanks.
From: jfearn [...] redhat.com
Download (untitled) / with headers
text/plain 292b
Hi, this seems to already be possible. perl -e 'use HTML::Element; %HTML::Element::optionalEndTag = (); print(new HTML::Element("div")->push_content(["p", "para 1"],new HTML::Element("input",type => "text",id => "fred"),)->as_HTML);' <div><p>para 1</p><input id="fred" type="text" /></div>
On Sat Apr 17 08:00:02 2010, jfearn wrote: Show quoted text
> Hi, this seems to already be possible. > > perl -e 'use HTML::Element; %HTML::Element::optionalEndTag = (); > print(new HTML::Element("div")->push_content(["p", "para 1"],new > HTML::Element("input",type => "text",id => "fred"),)->as_HTML);' > <div><p>para 1</p><input id="fred" type="text" /></div> >
I can see that will work for this purpose; but it's not clear from the documentation that you can safely alter %HTML::Element::optionalEndTag (i.e. %HTML::Tagset::optionalEndTag). The perldoc for HTML::Element suggests passing a reference to a locally defined hash (which I want to avoid having to do), while the perldoc for optionalEndTag in HTML::Tagset is garbled (has an example that refers to a different hashset). It's hard to remember now, two years later, but I think I was taking it that the hashes in HTML::Tagset should be treated as read only, though I confess it's not clear to me now why I thought that. I still think that HTML::Element is broken, as detailed in my original request.
Download (untitled) / with headers
text/plain 1.8k
On Mon Apr 19 05:20:59 2010, COLINFINE wrote: Show quoted text
> On Sat Apr 17 08:00:02 2010, jfearn wrote:
> > Hi, this seems to already be possible. > > > > perl -e 'use HTML::Element; %HTML::Element::optionalEndTag = (); > > print(new HTML::Element("div")->push_content(["p", "para 1"],new > > HTML::Element("input",type => "text",id => "fred"),)->as_HTML);' > > <div><p>para 1</p><input id="fred" type="text" /></div> > >
> > > I can see that will work for this purpose; but it's not clear from the > documentation that you can safely alter %HTML::Element::optionalEndTag > (i.e. %HTML::Tagset::optionalEndTag). > The perldoc for HTML::Element suggests passing a reference to a locally > defined hash (which I want to avoid having to do), while the perldoc for > optionalEndTag in HTML::Tagset is garbled (has an example that refers to > a different hashset). > > It's hard to remember now, two years later, but I think I was taking it > that the hashes in HTML::Tagset should be treated as read only, though I > confess it's not clear to me now why I thought that. > > I still think that HTML::Element is broken, as detailed in my original > request.
It's not broken, it's just slack, which is why we are all unhappy with HTML. $ perl -e 'use HTML::Element;print(new HTML::Element("div")->push_content(["p", "para 1"],new HTML::Element("input",type => "text",id => "fred"),)->as_HTML);' <div><p>para 1<input id="fred" type="text" /></div> This isn't wrong, the p is un-terminated which is "fine" and you can override that by playing with optionalEndTag. If you want XHTML then use as_XML, which gives this: $ perl -e 'use HTML::Element; print(new HTML::Element("div")->push_content(["p", "para 1"],new HTML::Element("input",type => "text",id => "fred"),)->as_XML);' <div><p>para 1</p><input id="fred" type="text" /></div> Which is all nice and tidy.
Download (untitled) / with headers
text/plain 652b
On Sat Apr 24 00:50:28 2010, jfearn wrote: Show quoted text
> > It's not broken, it's just slack, which is why we are all unhappy with
HTML. Show quoted text
> > $ perl -e 'use HTML::Element;print(new > HTML::Element("div")->push_content(["p", "para 1"],new > HTML::Element("input",type => "text",id => "fred"),)->as_HTML);' > > <div><p>para 1<input id="fred" type="text" /></div> > > This isn't wrong, the p is un-terminated which is "fine" and you can > override that by playing with optionalEndTag.
It's valid HTML. It's just got different semantics from what my Perl clearly expressed. That's broken. Show quoted text
> > If you want XHTML then use as_XML, which gives this:
Fair point.


This service is sponsored and maintained by Best Practical Solutions and runs on Perl.org infrastructure.

Please report any issues with rt.cpan.org to rt-cpan-admin@bestpractical.com.