Textpattern Forum

You are not logged in. Register | Login | Help

#1 2009-05-14 00:34:55

johnstephens
Plugin Author
From: Harrisonburg, VA
Registered: 2008-06-01
Posts: 834
Website

How do I strip <p> tags from an txp:excerpt w/o turning off Textile?

Howdy—

I’m presenting an excerpt inline and I want to get rid of the paragraph elements (<p></p>) generated by Textile— but I want to keep Textile on for the typography and stuff. Is there a way to do this?

I’m excerpting the same articles in another context, and I want those excerpts untouched, so changing the excerpts at the article level isn’t what I need.

Thanks!

Edit: The solution was right under my nose!

Last edited by johnstephens (2009-05-15 16:58:59)

Offline

#2 2009-05-14 01:13:06

immarabi
Member
Registered: 2008-04-29
Posts: 57

Re: How do I strip <p> tags from an txp:excerpt w/o turning off Textile?

Hi,

Just put notextile. and then one space before your text and it will remove the <p> tags.

Last edited by immarabi (2009-05-14 01:13:23)

Offline

#3 2009-05-14 01:39:28

johnstephens
Plugin Author
From: Harrisonburg, VA
Registered: 2008-06-01
Posts: 834
Website

Re: How do I strip <p> tags from an txp:excerpt w/o turning off Textile?

notextile. seems to eliminate all Textile, the same as choosing “Leave text untouched” under “Excerpt Markup”. As I said before, I want to keep Textile active for its typography and automatic escaping of &.

The other thing is that I don’t want to strip the paragraph element from the excerpt in every context, just in this listform:

<li><strong><txp:title />:</strong> <txp:excerpt /></li>

Elsewhere, I’m using the same excerpt, and I want to keep the <p> tags:

<h3>About this thing: </h3>
<txp:excerpt />

I expect that php-jujitsu may be needed to accomplish this.

Last edited by johnstephens (2009-05-14 01:39:42)

Offline

#4 2009-05-14 01:57:28

johnstephens
Plugin Author
From: Harrisonburg, VA
Registered: 2008-06-01
Posts: 834
Website

Re: How do I strip <p> tags from an txp:excerpt w/o turning off Textile?

I found a solution:

<txp:pax_grep from="|<p>|,|</p>|" to=","><txp:excerpt /></txp:pax_grep>

You can probably also use rah_replace for this, but I already have pax_grep active on my site.

Offline

#5 2009-05-14 02:01:54

jsoo
Developer
From: NC, USA
Registered: 2004-11-15
Posts: 1,730
Website

Re: How do I strip <p> tags from an txp:excerpt w/o turning off Textile?

Or a slightly simpler pattern:

<txp:pax_grep from="/<\/?p>/" to=""><txp:excerpt /></txp:pax_grep>

Txp tags not doing what you expect? Learn to use a tag trace. And the Tag Reference.

Offline

#6 2009-05-14 02:38:34

johnstephens
Plugin Author
From: Harrisonburg, VA
Registered: 2008-06-01
Posts: 834
Website

Re: How do I strip <p> tags from an txp:excerpt w/o turning off Textile?

Dude, why are you making my life more awesome all the live-long day?

Offline

#7 2009-05-14 07:15:04

jstubbs
Moderator
From: Hong Kong
Registered: 2004-12-13
Posts: 2,191
Website

Re: How do I strip <p> tags from an txp:excerpt w/o turning off Textile?

The various native methods are outlined in this TXP Tip.


TXP Tips | @txptips | Me | @jonathanstubbs | Github

TXP Builders – finely-crafted code, design and txp @txpbuilders

Offline

#8 2009-05-14 12:51:59

johnstephens
Plugin Author
From: Harrisonburg, VA
Registered: 2008-06-01
Posts: 834
Website

Re: How do I strip <p> tags from an txp:excerpt w/o turning off Textile?

Thanks, Jonathan— I’m a huge fan of TXP Tips, and I’ve seen this article before.

Those methods would be fine if the excerpt was never supposed to have <p> elements, but as I said before, I’m still using the normal <p>-wrapped excerpts for these articles in another context. Doing Textile-fu on the article level doesn’t allow for that differentiation, and requires thinking about it every time I write a new article in that section.

Offline

#9 2009-05-15 12:11:54

MyOwn31
New Member
From: Russia
Registered: 2008-10-15
Posts: 9

Re: How do I strip <p> tags from an txp:excerpt w/o turning off Textile?

Haven’t you tried putting a space before the excerpt text? This works on ThresoldState at least…

Offline

Board footer

Powered by FluxBB