View previous topic :: View next topic |
Author |
Message |
gtozzi Smarty Rookie
Joined: 18 Mar 2017 Posts: 8
|
Posted: Sun Oct 22, 2017 4:09 pm Post subject: {strip} bug? |
|
|
Hi there!
From what i read in the docs (the extra spaces are stripped), I would expect {strip} to "compress" spaces, but always keep at least one.
In fact, it looks like it just strips all spaces indiscriminately.
Let's consider this example:
Code: |
{strip}<input
type="text"
name="1234"
>{/strip}
|
The output will be:
Code: |
<inputtype="text"name="1234">
|
It would be nice if it kept just one space when multiple spaces are found, so the output would be
Code: |
<input type="text" name="1234">
|
If this is the intended behavior, then maybe add an option "keepone" or "one" to trigger this behavior instead and/or remove the "extra" word from the docs? |
|
Back to top |
|
bsmither Smarty Elite
Joined: 20 Dec 2011 Posts: 322 Location: West Coast
|
Posted: Mon Oct 23, 2017 12:04 am Post subject: |
|
|
That is certainly what the docs imply: removes all whitespace from the beginning and end of physical lines.
I guess it is what you define as 'extra'. The example makes it clear to me.
You might try:
Code: | {textformat wrap=8000}<input
type="text"
name="1234"
>{/textformat} |
|
|
Back to top |
|
gtozzi Smarty Rookie
Joined: 18 Mar 2017 Posts: 8
|
Posted: Mon Oct 23, 2017 12:33 am Post subject: |
|
|
Thank you, that's a good workaround. |
|
Back to top |
|
gtozzi Smarty Rookie
Joined: 18 Mar 2017 Posts: 8
|
Posted: Mon Oct 23, 2017 5:58 am Post subject: |
|
|
I correct myself: that does not work, because it also truncates text inside quotes indiscriminately. |
|
Back to top |
|
gtozzi Smarty Rookie
Joined: 18 Mar 2017 Posts: 8
|
Posted: Mon Oct 23, 2017 6:21 am Post subject: |
|
|
I am now using this
Code: |
/**
* Smarty plugin
*
* Leaves only one space where multiple spaces are found
*/
public static function mStrip($params, $content, $smarty, &$repeat) {
if ( ! isset($content) )
return;
$out = preg_replace('/\s+/m', ' ', $content);
if ( $out === null )
throw new \Exception('Error in estrip block');
return $out;
}
$this->_smarty->registerPlugin('block', 'estrip', ['Page','mStrip']);
|
|
|
Back to top |
|
bsmither Smarty Elite
Joined: 20 Dec 2011 Posts: 322 Location: West Coast
|
Posted: Mon Oct 23, 2017 3:05 pm Post subject: |
|
|
Truncates text?
Can you give an example? The example in the docs suggests that nothing but spaces and newlines are lost.
I can see where lines could be split at the exact length limit (your sample suggests final line lengths much shorter than 8000 characters).
I have not looked to see if there is a limit, or if zero would cause a line to never be broken. |
|
Back to top |
|
AnrDaemon Administrator
Joined: 03 Dec 2012 Posts: 1785
|
Posted: Tue Oct 24, 2017 2:25 am Post subject: |
|
|
I have a question: why do you think a generic text transformation would correctly apply to a formatted text?
It is more than likely it would break the formatting. Which you, evidently, proved yourself.
If you want to compress the XML, use XML tools. |
|
Back to top |
|
gtozzi Smarty Rookie
Joined: 18 Mar 2017 Posts: 8
|
Posted: Fri Oct 27, 2017 11:49 am Post subject: |
|
|
bsmither wrote: |
Can you give an example? The example in the docs suggests that nothing but spaces and newlines are lost.
|
That's right, but it does not account for HTML, so an output like
Code: |
<input
type="text"
name="1234"
data-comment="this
is a comment"
>
|
does not break textformat specifications, but makes it unsuitable for formatting HTML tags.
Quote: |
I have not looked to see if there is a limit, or if zero would cause a line to never be broken. |
That is what i would expect too, but actually zero causes every word to be placed on a new line. That is nice too. Having the support for a "-1" argument meaning "infinite" would be even nicer. |
|
Back to top |
|
gtozzi Smarty Rookie
Joined: 18 Mar 2017 Posts: 8
|
Posted: Fri Oct 27, 2017 11:51 am Post subject: |
|
|
AnrDaemon wrote: | I have a question: why do you think a generic text transformation would correctly apply to a formatted text?
It is more than likely it would break the formatting. Which you, evidently, proved yourself.
If you want to compress the XML, use XML tools. |
I had assumed that Smarty was designed to work with HTML. Sorry, my bad. |
|
Back to top |
|
AnrDaemon Administrator
Joined: 03 Dec 2012 Posts: 1785
|
Posted: Fri Oct 27, 2017 12:14 pm Post subject: |
|
|
Smarty does not "work with" anything at all.
It only "produces". Output. The format of that output is entirely up to you.
P.S.
What strip does is
Code: | return "preg_replace('!\s+!" . Smarty::$_UTF8_MODIFIER . "', {$params[1]},{$params[0]})"; |
|
|
Back to top |
|
U.Tews Administrator
Joined: 22 Nov 2006 Posts: 5068 Location: Hamburg / Germany
|
Posted: Sun Nov 12, 2017 12:16 am Post subject: |
|
|
The behaviour of {strip} has been changed since version 3.1.28 to keep multiline html tags intact. |
|
Back to top |
|
|