Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
Poll: useful 'escape' transforms
In 4.7 we have introduced a global escape
attribute, which applies to all tags (core and plugins) that don’t treat it natively. Its value is a comma-separated list of “transforms” that will be applied to the content in the given order. For example,
<txp:variable name="code" escape="trim, textile">
Hello, _world_!
</txp:variable>
<txp:variable name="code" escape="html" />
will output
<p>Hello, <em>world</em>!</p>
Currently (4.7-dev), the following transforms have been implemented:
html
(default): encode special HTML characters ("'&<>
);json
: JSON-encode, without the surrounding""
quotes;textile
: Textile the content;number
: output as numeric value (via PHPfloatval
);intval
: output as integer;strip
: strip tags;upper
,lower
: upper-/lower-case;trim
,ltrim
,rtrim
: remove surrounding space (on the left/right)
The question is: are these names intuitive enough, and what other transforms could be added to the list? Hurry up before 4.7 is out!
Offline
Re: Poll: useful 'escape' transforms
Move over smd_wrap, there’s a new kid in town.
All these seem reasonable to me. Is it worth considering some form of ucfirst and ucwords or do they not translate well to other languages? Wouldn’t have a clue what to name such transforms though.
The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.
Txp Builders – finely-crafted code, design and Txp
Online
Re: Poll: useful 'escape' transforms
Markdown?! ?
Offline
Re: Poll: useful 'escape' transforms
What about some of the sanitize options in smd_wrap, like url_title? Or fordb
(doSlash), or is that already catered for with the regular escape case?
The classic thing that happens in conjunction with strip_tags
is shortening to a number of words or characters. Not sure if that’s a candidate for an escape
attribute, but perhaps a transform
attribute.
The {liquid} templating tags have various string filters too…
TXP Builders – finely-crafted code, design and txp
Offline
#5 2017-12-12 13:13:54
- jpdupont
- Member
- Registered: 2004-10-01
- Posts: 752
Re: Poll: useful 'escape' transforms
All this seems perfect, and will allow to remove more and more plugins.
I do not know if this request falls under this attribute: “replace” str1 with str2 ???
Offline
Re: Poll: useful 'escape' transforms
Bloke wrote #308270:
Move over smd_wrap, there’s a new kid in town.
No worries, there will always be a need to cut|200|20w|…
:-)
Is it worth considering some form of ucfirst and ucwords or do they not translate well to other languages? Wouldn’t have a clue what to name such transforms though.
capitalize
, camelcase
? Some mb_
variant should be ok.
philwareham wrote #308271:
Markdown?! ?
In due course, admin side first :-)
jakob wrote #308272:
What about some of the sanitize options in smd_wrap, like url_title? Or
fordb
(doSlash), or is that already catered for with the regular escape case?
These are normally not used in core, but plugins are free to register their own global attributes for that.
The classic thing that happens in conjunction with
strip_tags
is shortening to a number of words or characters. Not sure if that’s a candidate for anescape
attribute, but perhaps atransform
attribute.The {liquid} templating tags have various string filters too…
jpdupont wrote #308273:
I do not know if this request falls under this attribute: “replace” str1 with str2 ???
These require extra parameters (cut length, strings to replace, etc), dunno how they should look in an attribute. If we decide (later) on a syntax, sure, but atm plugins territory for me (example).
Offline
#7 2017-12-12 14:03:02
- Algaris
- Member
- From: England
- Registered: 2006-01-27
- Posts: 553
Re: Poll: useful 'escape' transforms
+1 for Markdown please.
Offline
#8 2017-12-12 18:54:30
- GugUser
- Member
- From: Quito (Ecuador)
- Registered: 2007-12-16
- Posts: 1,473
Re: Poll: useful 'escape' transforms
What do you mean about this two examples?
<txp:smd_wrap transform='replace|regex|/"/|", textile'>
<txp:smd_wrap transform="textile,replace|regex|'<\/?p>'|">
Offline
Re: Poll: useful 'escape' transforms
GugUser wrote #308276:
What do you mean about this two examples?
<txp:smd_wrap transform='replace|regex|/"/|", textile'>...
That’s fine if one can replace the pipe |
delimiter with another symbol when needed (certainly the case with smd_wrap
). But in core we have no global delimiter
attribute atm, though it could be introduced if the community agrees on the syntax. But then the comma ,
should be configurable too…
Offline
Re: Poll: useful 'escape' transforms
I don’t like the pipe syntax, and separating out fields by a string is clunky anyway – see smd_if for a real-world example of how annoying this can be.
Right now, this is just about single simple transforms that can be performed for convenience in core without worrying about complicating things with extra arguments and delimiters. I’m fine with the ones Oleg’s already added. If there are any others, please add your thoughts here, but if it requires additional parameters, it won’t be considered (at least for now).
The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.
Txp Builders – finely-crafted code, design and Txp
Online
#11 2017-12-13 11:37:43
- uli
- Moderator
- From: Cologne
- Registered: 2006-08-15
- Posts: 4,306
Re: Poll: useful 'escape' transforms
Now that we’ll be able to even rtrim
and ltrim
white space, wouldn’t it be desirable to have the variable tag calculate
in order to do some simple, user defined maths?
E.g.
var “current iteration-no.” plus 1
var “current iteration-no.” < n
var “image width” minus 90px
etc.
In bad weather I never leave home without wet_plugout, smd_where_used and adi_form_links
Offline
Re: Poll: useful 'escape' transforms
uli wrote #308288:
Now that we’ll be able to even
rtrim
andltrim
white space, wouldn’t it be desirable to have the variable tagcalculate
in order to do some simple, user defined maths?
We do. :-) See example 1, for instance.
The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.
Txp Builders – finely-crafted code, design and Txp
Online