Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
[request] Remove paragraph tags from excerpts
I have written a small plugin for my own site that simply removes the opening and closing paragraph tags from an excerpt. This is my first plugin – an easy one but you have to walk before you can crawl!
Basically, it works exactly the same as the normal <code><txp:excerpt /></code> tag except that the opening <p>
and closing </p>
tags are removed. The idea is that I can then apply my own styled <p>
tag, and also include other bits and pieces within the same paragraph as the excerpt – rather than outside the paragraph.
This approach addresses my specific need. I’ve looked at a few of the plugins out there, but they all seem to do a lot more than I want whilst generating the excerpt from the article body. I like the semantic nature of having an excerpt as a distinctly separate piece of content, but just wanted more control over it.
I know that excerpts might not always start with a <p>
tag eg. when the author has used textile to use alternative formatting, and I also know that excerpts can be created without textile – I figure I can trap those ones in my plugin.
So, my questions are:
- has this already been done before? My searches haven’t shown anything similar, although I have seem some discussion about hacking the basic excerpt processing …
- is this worth releasing into the wild? I know how it works on my own site, but of course can’t control how it works on real sites created by others.
- what else do I need to know about Textpattern’s use of excerpts? As I say, this is my first attempt at a plugin, my knowledge of Textpattern’s internal workings is pretty slim (although I know I love it!) and I could be completely stuffing up some core functionality!
Thanks for any ideas.
Offline
Re: [request] Remove paragraph tags from excerpts
theres a plugin called etz_striptags which you can use to achieve a similar result, but it actually strips all tags out of the excerpt, including any textile-added formatting…
Offline
Re: [request] Remove paragraph tags from excerpts
Yep, I have seen that plugin. My problem was that I only really wanted to insert some additional content at the start and end of the excerpt – stripping out all tags runs the risk of corrupting the excerpts formatting completely.
As I say, I know that this will work for me because I can control how I create excerpts.
Offline
Re: [request] Remove paragraph tags from excerpts
I’d use it if you published it :)
Offline
Re: [request] Remove paragraph tags from excerpts
I just tried to get kgr_safe_excerpt and etz_striptags to work together (I am running an svn version a couple of days old) and the output was badly mangled. So after examining the code for both, I customized the return statement to
<code>return strip_tags(parse($excerpt));</code>
and finally got the validator to tell me that I wasn’t nesting paragraphs.
Offline
Re: [request] Remove paragraph tags from excerpts
Here is a modification to give you what you need. Just swap it with the existing code source.
<pre>
function etz_striptags($atts, $thing) {
extract(lAtts(array(‘allow’ => ‘’),$atts));
if (empty($allow)) {
return strip_tags(parse($thing));
}
else {
$allow = explode(‘,’, $allow);
foreach ($allow as $tag) {
$allow[$tag] = ‘<’.$tag.’>’;
}
$allow = implode($allow, ‘,’);
return strip_tags(parse($thing), $allow);
}
}
</pre>
To use wrap a block of text or a txp tag (excerpt for example) in <code><txp:etz_striptags></code>. The plugin now takes one argument, <code>allow</code>, a comma seperated list of tag names that you want retained within the section wrapped by the tag. All other tags will be stripped.
Example:
<code><txp:etz_striptags allow=“em,strong”><p><em>I hate paragraph tags, but like <em>emphasis</em> and <strong>strong</strong> tags!</p></code>.
Would give you: <code>I hate paragraph tags, but like <em>emphasis</em> and <strong>strong</strong> tags!</code>.
This modification worked well with my very limited testing.
Offline
#7 2006-10-17 15:56:35
- minimal design
- Member
- Registered: 2006-10-15
- Posts: 38
Re: [request] Remove paragraph tags from excerpts
Before I get crazy implementing this plugin, few questions:
#Is there a way to do this without plugin in 4.0.4?
#If no, anyone has it working on 4.0.4 – compatible?
#How would you get rid off the paragraph wrap in excerpt with just textile?
Thanks!
Offline
Re: [request] Remove paragraph tags from excerpts
Isn’t this feature already built into textpattern? “Article —> Advanced Options —> Excerpt (Dropdown) —> Leave text untouched”
I guess the only annoying thing is that you have to do it for every single article, but with etz_strip you’d still have to type it in all the time.
Cheers,
Proud Canadian. Toronto Locksmith , Actualize Consulting
Offline