WHITESPACE remove script / plugin

Have a question or a suggestion about a 3rd party addon module or plugin?
Let us know here.
Post Reply
mrmut
Forum Members
Forum Members
Posts: 33
Joined: Sun Jun 01, 2008 8:42 pm

WHITESPACE remove script / plugin

Post by mrmut »

Hello people!

Does anyone know if the WHITESPACE plugin has ever been finished? I have found the project here: http://dev.cmsmadesimple.org/projects/whitespace tho it appears there isn't anything there.

What I would need is some script that will stand before output and remove horizontal whitespaces from the outputted HTML.

Anyone knows about something like that?


Thank you.
fredp
Forum Members
Forum Members
Posts: 218
Joined: Sun Jul 27, 2008 1:36 am
Location: USA

Re: WHITESPACE remove script / plugin

Post by fredp »

Hi,

Is stripping whitespace worth the effort?

In any case, I think a User Defined Tag (UDT) might do what you want. There may be better ways to do this, but if you're in an experimental mood...   ;)

Warning: this is a quick and dirty proof-of-concept exercise (use at your own risk)!

On a test CMSMS installation:
1. Create a UDT containing the following code:

Code: Select all

$params['content'] = preg_replace('/(?:(?<=\>)|(?<=\/\>))(\s+)(?=\<\/?)/', '', $params['content']);
Note: I'm not sure if the regular expression above does what you want or need, but it's a start.

2. Add the UDT as an event handler to the 'ContentPostRender' event:
    a. go to "Extensions » Event Manager" on the Admin console
    b. click on "ContentPostRender" to bring up the "Edit Event Handler" page for that event
    c. Select your UDT, by name, from the pulldown at the bottom of the page and click "Add"

3. Visit your test site in a browser and see if the updated pages meet your needs.  If not, update the UDT code (regular expression or whatever) and review the site until you're happy with the results. 

If you decide you don't like this method, remove the UDT.

Hope this helps,
Fred
Nearly all men can stand adversity, but if you want to test a man's character, give him power.
- Abraham Lincoln
mrmut
Forum Members
Forum Members
Posts: 33
Joined: Sun Jun 01, 2008 8:42 pm

Re: WHITESPACE remove script / plugin

Post by mrmut »

Thanks! :)

This looks great at a glance. - Will do some testing, and report back afterwards.
mrmut
Forum Members
Forum Members
Posts: 33
Joined: Sun Jun 01, 2008 8:42 pm

Re: WHITESPACE remove script / plugin

Post by mrmut »

fredp wrote: Warning: this is a quick and dirty proof-of-concept exercise (use at your own risk)!

On a test CMSMS installation:
1. Create a UDT containing the following code:

Code: Select all

$params['content'] = preg_replace('/(?:(?<=\>)|(?<=\/\>))(\s+)(?=\<\/?)/', '', $params['content']);
Note: I'm not sure if the regular expression above does what you want or need, but it's a start.

2. Add the UDT as an event handler to the 'ContentPostRender' event:
    a. go to "Extensions » Event Manager" on the Admin console
    b. click on "ContentPostRender" to bring up the "Edit Event Handler" page for that event
    c. Select your UDT, by name, from the pulldown at the bottom of the page and click "Add"

Thank you Fred, this does work, tho I would need to tweak this a bit. - I would like to remove only the free lines of whitespace, between data. Ie:

LINK
                                                            LINK


I am not a programmer, can you please point me in the right direction where I would be able to find expressions so I could do this?


Thank you.  :)
fredp
Forum Members
Forum Members
Posts: 218
Joined: Sun Jul 27, 2008 1:36 am
Location: USA

Re: WHITESPACE remove script / plugin

Post by fredp »

mrmut wrote: ...
Thank you Fred, this does work, tho I would need to tweak this a bit. - I would like to remove only the free lines of whitespace, between data. Ie:

LINK
                                                            LINK
The example above makes things a bit more clear.  Thanks.
mrmut wrote: ...can you please point me in the right direction where I would be able to find expressions so I could do this?
Perhaps the following *untested* UDT code comes closer to what you want?
         

Code: Select all

$params['content'] =& preg_replace('/(?:\>|\/\>)\K(?:[\r\n]+\s+?([ \t]*))(?=\<\/?)/s', "\n$1", $params['content']);
I'd test it on multiple pages, to be sure they look and work as expected.  Using regular expressions to modify HTML can be... problematic.  ;) ;)

Hope this helps,
Fred
Nearly all men can stand adversity, but if you want to test a man's character, give him power.
- Abraham Lincoln
Jeff
Power Poster
Power Poster
Posts: 961
Joined: Mon Jan 21, 2008 5:51 pm
Location: MI

Re: WHITESPACE remove script / plugin

Post by Jeff »

I haven't used it but I have seen it in a couple templates so look at the tags {strip}{/strip}. http://www.smarty.net
mrmut
Forum Members
Forum Members
Posts: 33
Joined: Sun Jun 01, 2008 8:42 pm

Re: WHITESPACE remove script / plugin

Post by mrmut »

fredp wrote: Perhaps the following *untested* UDT code comes closer to what you want?        

Code: Select all

$params['content'] =& preg_replace('/(?:\>|\/\>)\K(?:[\r\n]+\s+?([ \t]*))(?=\<\/?)/s', "\n$1", $params['content']);
I've just tried the new code, and it seems this doesn't do anything to the page. - The output remains the same as without and with the UDT.

Any ideas? :~


Ajprog: I've also tried the smarty {strip} function, with which I get an error at the top of the page. Could you give me a link to the template that uses STRIP function so I can see how other people did it?


Thanks guys!
Jeff
Power Poster
Power Poster
Posts: 961
Joined: Mon Jan 21, 2008 5:51 pm
Location: MI

Re: WHITESPACE remove script / plugin

Post by Jeff »

As I am working tomorrow I will try and find it (4am now). If you can post the error I might know what is wrong.
fredp
Forum Members
Forum Members
Posts: 218
Joined: Sun Jul 27, 2008 1:36 am
Location: USA

Re: WHITESPACE remove script / plugin

Post by fredp »

mrmut wrote: I've just tried the new code, and it seems this doesn't do anything to the page. - The output remains the same as without and with the UDT.

Any ideas? :~
Hmmm.  That's odd.  I just tried it and it worked for me: empty/blank lines between HTML elements were removed from the source (as viewed in firefox3 via CTRL+U).  I'm using PHP 5.2.9.  Are you using PHP 5?  

You might verify that the UDT is still registered as an event handler for the 'ContentPostRender' event.  I've found that if you remove a UDT, then its event handler associations are dropped as well.

Also, I just cut and paste this code from my working UDT.  I removed the reference from the assignment, in case that was causing you trouble. See if it works for you:

Code: Select all

$params['content'] = preg_replace('/(?:\>|\/\>)\K(?:[\r\n]+\s+?([ \t]*))(?=\<\/?)/s', "\n$1", $params['content']);
Sorry, my brain has gone offline for the night...
Last edited by fredp on Fri Sep 25, 2009 8:59 am, edited 1 time in total.
Nearly all men can stand adversity, but if you want to test a man's character, give him power.
- Abraham Lincoln
Pierre M.

Re: WHITESPACE remove script / plugin

Post by Pierre M. »

Hello,

I've not read the entire thread, but what is the problem you are trying to solve ? and isn't it a webserver problem ?

If it is about less bytes on the wire from webserver to webbrowser I think this has been already solved for a long time by mod_deflate. Almost all xHTML transit compressed today.
If it is about sanitizing content to make it up to a low resource browser (low memory handheld?) this also can be done at the webserver level with mod_substitute at lightning fast compiled C speed.

Pierre M.
mrmut
Forum Members
Forum Members
Posts: 33
Joined: Sun Jun 01, 2008 8:42 pm

Re: WHITESPACE remove script / plugin

Post by mrmut »

The pages are gziped already, that is not the problem, but the code itself. - I would like that the output be without blank lines.

  Will try mod_substitute, looks this could work.



Thank you!

Pierre M. wrote: I've not read the entire thread, but what is the problem you are trying to solve ? and isn't it a webserver problem ?

If it is about less bytes on the wire from webserver to webbrowser I think this has been already solved for a long time by mod_deflate. Almost all xHTML transit compressed today.
If it is about sanitizing content to make it up to a low resource browser (low memory handheld?) this also can be done at the webserver level with mod_substitute at lightning fast compiled C speed.

Pierre M.
Post Reply

Return to “Modules/Add-Ons”