Textpattern CMS support forum

You are not logged in. Register | Login | Help

#21 2017-12-14 11:39:24

etc
Developer
Registered: 2010-11-11
Posts: 2,949
Website

Re: Poll: useful 'escape' transforms

Escape in images is done now, please test.

Also, if someone needs to extend the available functions list in <txp:evaluate query />, here is a tiny Easter eggs plugin. You can also enable CSS parsing and use css forms à la rah_external_output. I don’t think we will enable these “virtual” prefs in 4.7 yet, but feel free to test (at your own risk).

# Name: etc_easter_eggs v0.1 
# Type: Admin/Public plugin
# 
# Author: 
# URL: 
# Recommended load order: 5

# .....................................................................
# This is a plugin for Textpattern CMS - http://textpattern.com/
# To install: textpattern > admin > plugins
# Paste the following text into the 'Install plugin' box:
# .....................................................................

YToxMTp7czo0OiJuYW1lIjtzOjE1OiJldGNfZWFzdGVyX2VnZ3MiO3M6NjoiYXV0aG9yIjtz
OjA6IiI7czoxMDoiYXV0aG9yX3VyaSI7czowOiIiO3M6NzoidmVyc2lvbiI7czozOiIwLjEi
O3M6MTE6ImRlc2NyaXB0aW9uIjtzOjA6IiI7czo0OiJjb2RlIjtzOjMxODoicmVnaXN0ZXJf
Y2FsbGJhY2soJ2V0Y19wcmVmcycsICdwcmV0ZXh0X2VuZCcpOwoKZnVuY3Rpb24gZXRjX3By
ZWZzKCRldmVudCwgJHN0ZXApIHsKICAgIGdsb2JhbCAkcHJlZnM7CgogICAgLy8gUEhQIGZ1
bmN0aW9ucyB1c2VkIGluIDx0eHA6ZXZhbHVhdGUgLz46IGNvbW1hLXNlcGFyYXRlZCBsaXN0
IG9mICduYW1lJyBvciAnYWxpYXM6bmFtZScKICAgICRwcmVmc1sndHhwX2V2YWx1YXRlX2Z1
bmN0aW9ucyddID0gJ21kNSwgcmVwbGFjZTpwcmVnX3JlcGxhY2UnOwogICAgLy8gUGFyc2Ug
Y3NzPwogICAgJHByZWZzWydwYXJzZV9jc3MnXSA9IGZhbHNlOwp9IjtzOjQ6InR5cGUiO3M6
MToiMSI7czo1OiJvcmRlciI7czoxOiI1IjtzOjU6ImZsYWdzIjtzOjE6IjAiO3M6NDoiaGVs
cCI7YjowO3M6MzoibWQ1IjtzOjMyOiI3YzMwN2RkZTI2ZGM0YzZjMDk0YzNhZWJmYmQwMTEw
YyI7fQ==

etc_[ query | search | pagination | date | tree | cache ]

Offline

#22 2017-12-14 12:17:03

phiw13
Plugin Author
From: Japan
Registered: 2004-02-27
Posts: 1,546
Website

Re: Poll: useful 'escape' transforms

etc wrote #308307:

Escape in images is done now, please test.

Will do so tomorrow morning :-)

Offline

#23 2017-12-15 12:43:45

phiw13
Plugin Author
From: Japan
Registered: 2004-02-27
Posts: 1,546
Website

Re: Poll: useful 'escape' transforms

etc wrote #308307:

Escape in images is done now, please test.

It works nicely. Of course (and this goes for any place where escape="textile" is used), now we have that nice side effect that the string to which it is applied is wrapped in a <p />.
so for my example above, the output is:

<figcaption><p>a <em>test</em> image - something <strong>bold<strong></p></figcaption>

Nothing annoying for my use case, though.

—-
BTW – speaking of evaluate, I spotted this in the templates for the Textpattern main website:

width="<txp:evaluate query='ceiling(<txp:image_info type="w" />div2)' />"

Amazingly, I even manage to understand what it does… A question though, does the number in the div2 need to be an integer? Or can it be something like div1.5 ? It did not immediately work in a quick test (the output was blank), but then I had some other issues with what I was trying and I did not have time to investigate that part further. Populating the srcset attribute with multiple sizes can be giant pain.

Offline

#24 2017-12-15 13:17:03

etc
Developer
Registered: 2010-11-11
Posts: 2,949
Website

Re: Poll: useful 'escape' transforms

phiw13 wrote #308313:

It works nicely. Of course (and this goes for any place where escape="textile" is used), now we have that nice side effect that the string to which it is applied is wrapped in a <p />.

Dunno what to do with this, prepend a space, perhaps?

<txp:evaluate escape="textile" wraptag="figcaption"> <txp:image_info type="caption" /></txp:evaluate>

BTW – speaking of evaluate, … does the number in the div2 need to be an integer?

No, <txp:evaluate query='ceiling(2.718 div 1.618)' /> is fine.


etc_[ query | search | pagination | date | tree | cache ]

Offline

#25 2017-12-15 13:45:48

phiw13
Plugin Author
From: Japan
Registered: 2004-02-27
Posts: 1,546
Website

Re: Poll: useful 'escape' transforms

etc wrote #308314:

Dunno what to do with this, prepend a space, perhaps?

<txp:evaluate escape="textile" wraptag="figcaption"> <txp:image_info type="caption" /></txp:evaluate>…

Winner! <txp:evaluate /> is truly magic.

No, <txp:evaluate query='ceiling(2.718 div 1.618)' /> is fine.

Great, thanks. I’ll play with that.

Offline

#26 2017-12-15 14:48:11

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 8,458
Website

Re: Poll: useful 'escape' transforms

phiw13 wrote #308315:

Winner! <txp:evaluate /> is truly magic.

Seconded!


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

Offline

#27 2017-12-15 15:13:54

philwareham
Core designer
From: Farnham, Surrey, UK
Registered: 2009-06-11
Posts: 3,093
Website

Re: Poll: useful 'escape' transforms

I think the evaluate tag doc probably needs to be fleshed out a bit further. Doesn’t seem to capture how useful this tag is right now (and I don’t fully understand the tag myself so I can’t write about it).

Offline

#28 2017-12-17 16:11:05

etc
Developer
Registered: 2010-11-11
Posts: 2,949
Website

Re: Poll: useful 'escape' transforms

etc wrote #308314:

Dunno what to do with this, prepend a space, perhaps?

<txp:evaluate escape="textile" wraptag="figcaption"> <txp:image_info type="caption" /></txp:evaluate>

Another possibility is to consider any undocumented escape value xyz as “unwrap <xyz /> tag”. Then the example above would become

<txp:image_info type="caption" escape="textile, p" wraptag="figcaption" />

A working commit is ready, I’m just not sure whether this is not too confusing.

Edit: BTW, escape="img" would mean “remove images” (from Textile-formatted text), which could be handy in excerpts.


etc_[ query | search | pagination | date | tree | cache ]

Offline

#29 2017-12-17 22:48:27

phiw13
Plugin Author
From: Japan
Registered: 2004-02-27
Posts: 1,546
Website

Re: Poll: useful 'escape' transforms

etc wrote #308318:

Another possibility is to consider any undocumented escape value xyz as “unwrap <xyz /> tag”.

… I’m just not sure whether this is not too confusing.

That is certainly interesting, and powerful. Confusing? Just a little, at first sight.

(I find myself increasingly in need to document my code snippets. The other day I was looking at some category related snippet that I coded some month ago. I had to read it over a few times before understanding what I intended to do).

Offline

#30 2017-12-18 09:14:51

etc
Developer
Registered: 2010-11-11
Posts: 2,949
Website

Re: Poll: useful 'escape' transforms

Bloke wrote #308299:

Possibly some way to remove newlines but preserve spaces? Is that helpful, as distinct from trim?

Yes, I think, e.g. for “inline” Textile. I have added implode value (the name to debate) that preg-replaces \s+ with a space and also prepends a space. So,

*This* is

a _test_

becomes first (space)*This* is a _test_ and then <strong>This</strong> is a <em>test</em> when passed through escape="implode, textile".


etc_[ query | search | pagination | date | tree | cache ]

Offline

Board footer

Powered by FluxBB