WHITESPACE remove script / plugin
WHITESPACE remove script / plugin
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.
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.
Re: WHITESPACE remove script / plugin
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:
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
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']);
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
- Abraham Lincoln
Re: WHITESPACE remove script / plugin
Thanks! 
This looks great at a glance. - Will do some testing, and report back afterwards.

This looks great at a glance. - Will do some testing, and report back afterwards.
Re: WHITESPACE remove script / plugin
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:Note: I'm not sure if the regular expression above does what you want or need, but it's a start.Code: Select all
$params['content'] = preg_replace('/(?:(?<=\>)|(?<=\/\>))(\s+)(?=\<\/?)/', '', $params['content']);
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.

Re: WHITESPACE remove script / plugin
The example above makes things a bit more clear. Thanks.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
Perhaps the following *untested* UDT code comes closer to what you want?mrmut wrote: ...can you please point me in the right direction where I would be able to find expressions so I could do this?
Code: Select all
$params['content'] =& preg_replace('/(?:\>|\/\>)\K(?:[\r\n]+\s+?([ \t]*))(?=\<\/?)/s', "\n$1", $params['content']);


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
- Abraham Lincoln
Re: WHITESPACE remove script / plugin
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
Re: WHITESPACE remove script / plugin
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.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']);
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!
Re: WHITESPACE remove script / plugin
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.
Re: WHITESPACE remove script / plugin
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?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? :~
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']);
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
- Abraham Lincoln
Re: WHITESPACE remove script / plugin
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.
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.
Re: WHITESPACE remove script / plugin
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!
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.