1 of 2
1
XHTML Formatting without the <p>
Posted: 12 March 2006 08:17 PM   [ Ignore ]  
Lab Technician
Avatar
RankRankRankRank
Total Posts:  1183
Joined  01-05-2006

Hi,
I love XHTML formatting because it converts special characters into their hex value, curly quotes are the perfect example of this.  My problem is that I want to use XHTML formatting without wrapping everything in a <p> because my content is being placed in an <li>.  So right now I’m getting this:

<li><p>this is &#8220;content&#8221;</p></li>

and I’d like to get this.

<li>this is &#8220;content&#8221;</li>

Thanks
Mark

Update I’ve created a plugin that does just this, use it as follows {exp:strip_p}....{/exp:strip_p}

File Attachments
pi.strip_p_103.zip  (File Size: 1KB - Downloads: 439)
 Signature 

================================================
    Mark Huot
    http://markhuot.com
================================================

Profile
 
 
Posted: 12 March 2006 09:02 PM   [ Ignore ]   [ # 1 ]  
Moderator
Avatar
RankRankRankRankRankRankRankRank
Total Posts:  32132
Joined  05-14-2004

I don’t get this, and I use xhtm formatting with lists all the time.  What build of EE are you on and in what way are you entering the text?

 Signature 
Profile
MSG
 
 
Posted: 12 March 2006 09:06 PM   [ Ignore ]   [ # 2 ]  
Administrator
Avatar
RankRankRankRankRankRankRank
Total Posts:  15293
Joined  06-03-2002

There are three ways I see to do this.  One is sketchy but quick, the other takes moderate work on your part each time you make an entry that uses that field, and the last one takes more extensive effort—but only one time up front.

Sketchy: Open core.typography.php and near the very top, around line 30, you’ll see var $single_line_pgf = TRUE;.  Change that to FALSE.  The sketchy part is that you will have to keep up with this everytime you update, and it can’t be guaranteed that this change will always work for future builds.  Also, that will affect all of your fields that use Auto-XHTML.  You will have to manually add <p> tags to single lines of text when you want them.

Moderate: Turn formatting off for that field, and keep a chart handy for your character entities to replace special characters manually.

More Extensive: Create an extension that strips <p> tags from that field using the typography_parse_type_start hook.

 Signature 
Profile
MSG
 
 
Posted: 10 October 2006 05:51 AM   [ Ignore ]   [ # 3 ]  
Grad Student
Avatar
Rank
Total Posts:  84
Joined  09-25-2006
More Extensive: Create an extension that strips <p> tags from that field using the typography_parse_type_start hook.

hi ... does anyone have any examples of how to go about creating an extension that will do this?

thanks!

 Signature 

gravity is a myth ... the earth sucks gulp

Profile
 
 
Posted: 20 October 2006 12:10 PM   [ Ignore ]   [ # 4 ]  
Lab Technician
Avatar
RankRankRankRank
Total Posts:  1183
Joined  01-05-2006

I’ve created a plugin to solve this problem.  You can find it at the top of this thread.

 Signature 

================================================
    Mark Huot
    http://markhuot.com
================================================

Profile
 
 
Posted: 03 November 2006 06:43 AM   [ Ignore ]   [ # 5 ]  
Lab Assistant
RankRank
Total Posts:  189
Joined  10-09-2006

I took the liberty to adjust my own copy:

I replaced

$this->return_data = preg_replace("/(?:^<p.*?>|<\/p>\s*$)/s", "", $str);


with

$this->return_data = preg_replace("/(?:^<p.*?>|\n<\/p>\s*$)/s", "", $str);


Note the \n.

This way it also removes the newline from the source.

 Signature 

G - B - O
___________
Version 1.6.4

Profile
 
 
Posted: 03 November 2006 08:10 AM   [ Ignore ]   [ # 6 ]  
Lab Technician
Avatar
RankRankRankRank
Total Posts:  1183
Joined  01-05-2006

I actually did the same, just forgot to upload it:

$this->return_data = preg_replace("/(?:^<p.*?>|\s*<\/p>\s*$)/s", "", $str);

That way it will pull the paragraph right up against the end of the content (in case there’s some tabs or spaces on the end).  I’ll upload a newer version later today once I get a few more things straightened out with it.

 Signature 

================================================
    Mark Huot
    http://markhuot.com
================================================

Profile
 
 
Posted: 03 November 2006 08:26 AM   [ Ignore ]   [ # 7 ]  
Lab Assistant
RankRank
Total Posts:  189
Joined  10-09-2006

AFAIK this would only remove trailing spaces instead of linebreaks, or is it any whitespace (including linebreaks?) ?

 Signature 

G - B - O
___________
Version 1.6.4

Profile
 
 
Posted: 03 November 2006 08:35 AM   [ Ignore ]   [ # 8 ]  
Lab Technician
Avatar
RankRankRankRank
Total Posts:  1183
Joined  01-05-2006

with the ”/s” modifier the period (.) and space (\s) patterns will match newlines, while, like you said, without the ”\s” modifier they wouldn’t.

So, yes, it will match any whitespace (tabs, newlines, carriage returns, spaces, etc) in my example.  I would recommend the ”\s” way only because on some systems it may not be a ”\n” it might be a ”\r”.

 Signature 

================================================
    Mark Huot
    http://markhuot.com
================================================

Profile
 
 
Posted: 03 November 2006 08:50 AM   [ Ignore ]   [ # 9 ]  
Lab Assistant
RankRank
Total Posts:  189
Joined  10-09-2006

Great!
Thanks for explaing so clearly.

 Signature 

G - B - O
___________
Version 1.6.4

Profile
 
 
Posted: 03 November 2006 09:15 AM   [ Ignore ]   [ # 10 ]  
Lab Technician
Avatar
RankRankRankRank
Total Posts:  1183
Joined  01-05-2006

1.0.2 is up and addresses what GBO and I were talking about.

 Signature 

================================================
    Mark Huot
    http://markhuot.com
================================================

Profile
 
 
Posted: 15 November 2006 08:47 AM   [ Ignore ]   [ # 11 ]  
Lab Assistant
RankRank
Total Posts:  189
Joined  10-09-2006

Is it just me, or does this pi give problems in combination with the

{weblog:entries backspace="#"}

part?

thanks.

 Signature 

G - B - O
___________
Version 1.6.4

Profile
 
 
Posted: 15 November 2006 09:01 AM   [ Ignore ]   [ # 12 ]  
Lab Technician
Avatar
RankRankRankRank
Total Posts:  1183
Joined  01-05-2006

It shouldn’t affect the backspace attribute.  What kinds of problems are you having?

 Signature 

================================================
    Mark Huot
    http://markhuot.com
================================================

Profile
 
 
Posted: 15 November 2006 10:28 AM   [ Ignore ]   [ # 13 ]  
Lab Assistant
RankRank
Total Posts:  189
Joined  10-09-2006

The ending of (one of) my template(s) looks like this:

<p>

{exp:strip_p}{text_body{my_lang}}{/exp:strip_p}

</p>
      <
a href="#top" class="to_top" target="_top">{top{my_lang}}</a>
    <
div id="divider"></div>{/exp:weblog:entries}

In the weblog:entries tag i use backspace=“28” to remove the last “divider”-div plus the preceeding spaces.
That works as expected. Only the trailing </p> that goes with {text_body{my_lang}} isn’t stripped, so i end up with an overload of </p> tags ...

If i remove the backslash it works as expected, but i’m stuck with a div too many ...

Thanks ...

 Signature 

G - B - O
___________
Version 1.6.4

Profile
 
 
Posted: 15 November 2006 11:08 AM   [ Ignore ]   [ # 14 ]  
Lab Technician
Avatar
RankRankRankRank
Total Posts:  1183
Joined  01-05-2006

Version 1.0.3 should fix this problem.  For some reason when you use backspace=”“ it converts all slashes to / while without it doesn’t.  Very strange.

 Signature 

================================================
    Mark Huot
    http://markhuot.com
================================================

Profile
 
 
Posted: 15 November 2006 11:14 AM   [ Ignore ]   [ # 15 ]  
Lab Assistant
RankRank
Total Posts:  189
Joined  10-09-2006

Great. “Glad” it wasn’t me, but glad to find it out.

 Signature 

G - B - O
___________
Version 1.6.4

Profile
 
 
Posted: 04 September 2007 05:05 AM   [ Ignore ]   [ # 16 ]  
Research Assistant
Avatar
RankRankRank
Total Posts:  486
Joined  10-14-2005

I was just about to mod Ricks <p> to <br> plug-in and cam across this. Very handy. Like Mark I need to strip paragraphs from around a custom field that I’m outputting into a list.

smile

 Signature 

Nathan Pitman

Nine Four Ltd - a member of the EEPro Network

Profile
 
 
Posted: 04 September 2007 06:11 PM   [ Ignore ]   [ # 17 ]  
Lab Assistant
RankRank
Total Posts:  110
Joined  03-14-2007

Does this plugin strip all <p> tags in the field, or just the <p>...</p> pair that EE wraps the field in?

Profile
 
 
Posted: 05 September 2007 08:05 AM   [ Ignore ]   [ # 18 ]  
Lab Technician
Avatar
RankRankRankRank
Total Posts:  1183
Joined  01-05-2006

just the opening and closing <p>.

 Signature 

================================================
    Mark Huot
    http://markhuot.com
================================================

Profile
 
 
   
1 of 2
1
 
Post Marker Legend
New Topic New posts Hot Topic Hot Topic with new posts New Poll New Poll Moved Topic Moved Topic Sticky Topic Sticky topic
Old Topic No new posts Hot Old Topic Hot Topic with no new posts Old Poll Old Poll Closed Topic Closed Topic Announcement Announcements
Theme
Change Theme
Visitor Statistics
The most visitors ever was 1149, on July 16, 2007 10:33 AM
Total Registered Members: 62658 Total Logged-in Users: 44
Total Topics: 77195 Total Anonymous Users: 19
Total Replies: 416715 Total Guests: 248
Total Posts: 493910    
Members ( View Memberlist )