Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2021-09-23 10:47:41

demoncleaner
Plugin Author
From: Germany
Registered: 2008-06-29
Posts: 228
Website

Cannot get escaping "tidy, textile" working

<txp:body escape="tidy, textile"/>

Should give me the content of the body field without the surrounding <p>, correct?
In my case it seems not to work at all and I still get surrounding <p> and I am wondering why.

This works fine though:

<txp:body escape="tidy, p"/>

Offline

#2 2021-09-23 11:40:35

etc
Developer
Registered: 2010-11-11
Posts: 5,642
Website GitHub

Re: Cannot get escaping "tidy, textile" working

demoncleaner wrote #331650:

<txp:body escape="tidy, textile"/>...

Should give me the content of the body field without the surrounding <p>, correct?

No, it should textile the output of <txp:body /> (without wrapping it with <p>) after some whitespace normalization (tidy). But <txp:body /> output is already textiled, so escape has no effect here.

Offline

#3 2021-09-23 12:59:22

demoncleaner
Plugin Author
From: Germany
Registered: 2008-06-29
Posts: 228
Website

Re: Cannot get escaping "tidy, textile" working

OK. Thanks, I almost understand.

But shouldn´t

<txp:variable name="test" value='<txp:body/>' escape="tidy, textile" output/>

work than?

But that gives me still surounding <p>.
What am I missing?

Or let me ask in a different way:
What would I have to do when I want the contents of the body field output without any surounding <p>.
(Changing the format in the backend cannot be an option unfortunately.)

Last edited by demoncleaner (2021-09-23 13:01:44)

Offline

#4 2021-09-23 14:07:37

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 12,306
Website GitHub

Re: Cannot get escaping "tidy, textile" working

The Body field (and Excerpt) already has Textile applied, and already has the surrounding ‘p’ tags.

Telling escape to tidy it (remove newlines and add a preceding space) and then pass it through Textile is a waste of time, since it’s already been passed through Textile. The <txp:body> tag actually outputs the Body_html field (at least, if it doesn’t, it should!). It applies Textile on save, not on output, for performance reasons. Additionally, you might get odd results if it encounters something in the HTML that it doesn’t quite understand.

In your <txp:variable> example, the same applies. You’re populating the variable with HTML from the article body, and then asking the variable to pass its content through Textile. That’ll have no effect.


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

#5 2021-09-23 14:12:46

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 12,306
Website GitHub

Re: Cannot get escaping "tidy, textile" working

demoncleaner wrote #331655:

What would I have to do when I want the contents of the body field output without any surounding <p>.

<txp:custom_field name="body" escape="tidy, textile" />

:)

(though that’ll have a performance impact on your pages as it re-Textile’s the entire article on the fly)

Last edited by Bloke (2021-09-23 14:13:38)


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

#6 2021-09-23 15:10:34

demoncleaner
Plugin Author
From: Germany
Registered: 2008-06-29
Posts: 228
Website

Re: Cannot get escaping "tidy, textile" working

OK. I see =). Thank you.
Maybe then that´s a bit misleading here for somebody that has no clue how exactly it works in the background.

https://docs.textpattern.com/tags/learning/#available-escape-values

Remove spaces/newlines, prepend a single space to remove the surrounding <p> tag, then Textile the content.

I thought I can use it in a situation where I just use the body field for just one sentence or so and do not want it to be wrapped in <p>. Get rid of it and textile it again.

Of course changing the format in the backend is an option as well. But I normally try to avoid it because this can easily be overseen by somebody who is not so much into textpattern.

At least I know now why it is not working. Think I change my idea of how to use the body field in those cases and better make use of a custom_field. Thanks again!

Last edited by demoncleaner (2021-09-23 15:10:53)

Offline

#7 2021-09-24 11:34:59

etc
Developer
Registered: 2010-11-11
Posts: 5,642
Website GitHub

Re: Cannot get escaping "tidy, textile" working

demoncleaner wrote #331658:

Maybe then that´s a bit misleading here for somebody that has no clue how exactly it works in the background.

The docs are a bit long, but they do state that

global attributes cannot intervene in a tag’s internal processing and are applied only to the tag’s output.

So, when the global escape="textile" is applied to <txp:body />, it is too late, it will just be textiled a second time.

Offline

#8 2021-09-25 04:47:52

demoncleaner
Plugin Author
From: Germany
Registered: 2008-06-29
Posts: 228
Website

Re: Cannot get escaping "tidy, textile" working

OK. Got it. So as far as I can see then in my scenario escape="tidy, p" or better just using a custom_field instead of body would be the weapon of choice. Thanks guys.

Offline

#9 Yesterday 21:21:06

bici
Member
From: vancouver
Registered: 2004-02-24
Posts: 2,231
Website Mastodon

Re: Cannot get escaping "tidy, textile" working

actually are there not plenty of situations where a designer would want content output to be free of any <p> tags. The person inputing text may not toggle the text in the Body and Excerpt fields to NOT use Textile so the code could force the striping of the <P> tags: So would this be correct?

<txp:body escape="tidy, p"/>
<txp:excerpt escape="tidy, p"/>

…. texted postive

Offline

#10 Today 07:57:47

jakob
Admin
From: Germany
Registered: 2005-01-20
Posts: 5,132
Website GitHub

Re: Cannot get escaping "tidy, textile" working

bici wrote #342005:

actually are there not plenty of situations where a designer would want content output to be free of any <p> tags. The person inputing text may not toggle the text in the Body and Excerpt fields to NOT use Textile so the code could force the striping of the <P> tags: So would this be correct?

<txp:body escape="tidy, p"/>...

I’m not sure if I fully understand your situation. Are you just trying to strip the surrounding p tag or all tags created as a result of textiling. If the latter, you can do:

<txp:excerpt escape="tags" />

You’ll still get the benefits of character conversions from textiling but any formatting added that produces html tags will be stripped.

If it’s just the surrounding beginning and ending p tag you want to remove, I thought the tidy option did that, though in the other thread I found it was necessary to use p as well.


TXP Builders – finely-crafted code, design and txp

Offline

#11 Today 16:33:16

bici
Member
From: vancouver
Registered: 2004-02-24
Posts: 2,231
Website Mastodon

Re: Cannot get escaping "tidy, textile" working

I can foresee being able to do both. Yesterday I have used the <txp:body escape="tidy, p"/> option on a new site where I am outputting short blocks of text, as quotes to a footer area. Those Body and Excerpts texts are to be textile free, so that the user cannot cause a css fail on output. Your excape tags example is new to me. and I can also see where that might be useful where I wish to have long strings of texts used in “quotes” to be textile free no matter what the user does. Thank-you


…. texted postive

Offline

#12 Today 18:00:03

Vienuolis
Member
From: Vilnius, Lithuania
Registered: 2009-06-14
Posts: 327
Website GitHub GitLab Mastodon Twitter

Re: Cannot get escaping "tidy, textile" working

The wrapping behavior appears to have been changed upgrading 4.8.8 to 4.9.0. However, if you only want to avoid excess ‹p› when transferring from small input fields while retaining the Textile transformation, simply insert a space at the beginning of the field. Start an entry with a space! E. g.

<figcaption><p>Some description</p></figcaption>

would be wrapped in ‹p› by Textile from Images: Edit: Caption, and

<figcaption> Some description </figcaption>

will not.

Last edited by Vienuolis (Today 18:01:57)

Offline

Board footer

Powered by FluxBB