Forums / Developer / Tidy output extension?

Tidy output extension?

Author Message

Andrew K

Tuesday 30 January 2007 3:02:40 pm

I was wondering if there is already or anyone would be interested in an extension that took all of the potentially messy html outputted by eZ and tidy'ed it up (probably using the tidy engine). If there is not one already out there, I thought I'd try my hand at creating it. Let me know your thoughts.

In case you're not familiar with Tidy... http://tidy.sourceforge.net/

--Andrew

Stuart Fenton

Wednesday 31 January 2007 12:48:30 am

It's a nice idea as long as it can be placed between the html generation and the cache, compile.

Regards
Fats

-- Stuart

stuart@grandmore.com
http://www.grandmore.com

Xavier Dutoit

Wednesday 31 January 2007 1:20:07 am

They aren't any reason the code generated by ez is messy.

If it it, modify the templates you don't like.

X+

http://www.sydesy.com

Xavier Dutoit

Wednesday 31 January 2007 1:22:14 am

By modify, I meant override. You can override about any template that output html and replace it with xhtml code you want.

I'm able to produce xhtml 1.1 code (or could if I modify a few template and accept not to use target for the links for instance).

X+

http://www.sydesy.com

Andrew K

Wednesday 31 January 2007 8:00:59 am

I'm not really concerned with the validity/compliance of the xhtml. Just the aesthetics of the actual outputted code.

For example, a template in eZ may output the following:

<div class='some-class'>
<div class='some-other-class'>

<ol>
<li>item 1<li>item 2<li>item 3

</ol>


</div>

</div>

Which could be cleaned up by Tidy to look like:

<div class='some-class'>
   <div class='some-other-class'>
      <ol>
         <li>item 1
         <li>item 2
         <li>item 3
      </ol>
   </div>
</div>

Which would be much easier to look at when you are debugging templates and just generally easier to look at when viewing the code.

Andrew K

Wednesday 31 January 2007 8:08:42 am

Fats,

Is it possible for a eZ extension to place something between the html generation and cache? Or would this have to be a kernel hack? This would be my first attempt a making any kind of extension. Forgive my ignorance.

--Andrew

kracker (the)

Wednesday 31 January 2007 8:23:20 am

It's sure an interesting idea!

Have you looked into where you might insert this step in the process?
I'd guess that there must be a place where this can be augmented,
but which one ...

//kracker

<i>Busdriver - Stylin' Under Pressure</i>

Member since: 2001.07.13 || http://ezpedia.se7enx.com/

Andrew K

Wednesday 31 January 2007 8:55:05 am

That's where I'm at a loss. I could use some direction, there.

--Andrew

Paul Forsyth

Wednesday 31 January 2007 9:17:10 am

One way around this issue is to use a 'post' html solution.

This firefox extension 'pretty prints' the html:

http://jennifermadden.com/scripts/ViewRenderedSource.html

paul

Andrew K

Wednesday 31 January 2007 9:35:03 am

Paul,

I agree this is a good alternative for debugging. I guess I just want the output code of my site to look super clean to everyone.

Thanks for the recommendation.

--Andrew

Paul Forsyth

Wednesday 31 January 2007 9:55:35 am

Its a challenging task given the number of templates going into a single html page.

eZ operators often leave white space in the html output. Even template comments {* *} do that which makes output *very* hard to control. I often have to put particular statements on a single line to avoid browser incompatibilities.

paul

Paul Forsyth

Wednesday 31 January 2007 9:56:30 am

actually, thinking more about this there should be no reason for not having an operator like:

{$module_result.content|tidy}

in the main pagelayout.

hmmm...

Andrew K

Wednesday 31 January 2007 10:06:12 am

Oh yeah, I like that idea. I was thinking along a similar line. By capturing the entire output and running tidy on it before it was sent to the browser.

So that wouldn't necessarily be an extension, right or would it? I guess I just need a place to start diving in.

--Andrew

Andrew K

Wednesday 31 January 2007 10:13:44 am

Ok. I did some browsing and concluded that this would be a custom template operator. I'll start there. Thanks for all of the input, it's been very helpful!

--Andrew

Bruce Morrison

Wednesday 31 January 2007 2:36:17 pm

Howdy

Unfortinually

{$module_result.content|tidy}

may not work as tidy is treats the input as a complete HTML page and code only produces a "content" HTML fragment. I suspect that running tidy on this will cause it to insert extra html, body, head etc tags. (Though the "show-body-only" option may help here)

Whats required in eZ is thge ability to do post template generation processing ( smarty has this ability http://smarty.php.net/manual/en/api.register.postfilter.php) and it is great for this type of thing.

Cheers
Bruce

My Blog: http://www.stuffandcontent.com/
Follow me on twitter: http://twitter.com/brucemorrison
Consolidated eZ Publish Feed : http://friendfeed.com/rooms/ez-publish

Andrew K

Wednesday 31 January 2007 2:53:41 pm

Bruce,

So are you saying that eZ does not have the ability to do post template generation processing, not even through an extention?

--Andrew

Andrew K

Wednesday 31 January 2007 2:59:14 pm

Looking at the Tidy Man page, it looks like Bruce is right about the 'show-body-only' option. I think that will solve tidy seeing the input as an entire page.

Thanks Bruce.

--Andrew

Bruce Morrison

Wednesday 31 January 2007 3:07:23 pm

@Andrew

<i>So are you saying that eZ does not have the ability to do post template generation processing, not even through an extention?</i>

Well I haven't checked the code but I doubt very much that the hooks are present to be able to do this in an extension. I suspect that the kernel would have to be hacked to allow for this functionallity.

Cheers
Bruce

My Blog: http://www.stuffandcontent.com/
Follow me on twitter: http://twitter.com/brucemorrison
Consolidated eZ Publish Feed : http://friendfeed.com/rooms/ez-publish

Paul Forsyth

Thursday 01 February 2007 2:15:32 am

I dont think it would be too hard. Once you drop into the operator code and php you should be able to filter the html into a form tidy will accept.

Perhaps follow these steps:

1. Invoke {$module_result.content|tidy}
2. In operator php code wrap the ez html with appropriate html tags: <html><body>{$module_result.content}</body></html>
3. Allow tidy to do its job.
4. Receive formatted html and remove the added html from its output.
5. Return the formatted html.

Since eZ components has a new template engine i dont believe the current version will be improved. However, im not sure if the eZc has the necessary hooks.

Paul

Bruce Morrison

Thursday 01 February 2007 7:08:11 pm

Hi Paul

I reckon that would do the trick. Might be easier to wrap the tidy input comments .e.g.

<!-- Start pre tidy -->
{$module_result.content}
<!-- End pre tidy -->

and then remove above and below the comments in the output.

Of course an operator on {$module_result.content} will only "tidy" that portion of the HTML. The rest of pagelayout.tpl will not be effected.

Cheers
Bruce

My Blog: http://www.stuffandcontent.com/
Follow me on twitter: http://twitter.com/brucemorrison
Consolidated eZ Publish Feed : http://friendfeed.com/rooms/ez-publish