views:

577

answers:

1

Hi

How do I tell the YUI-Editor to enclose all text into <p></p> and use <p></p> instead of <br> if the user issues a linebreak?

Here comes an example to illustrate what I'm trying to do:

Instead of this:

The quick brown fox<br>jumps over the lazy dog

I would like to have this:

<p><p>The quick brown fox</p><p>jumps over the lazy dog</p></p>

Any idea how to do this besides parsing the whole html before saving it and finding-replacing the tags?

Update: I just noticed, that the YUI Editor automagically issues <p></p> on linebreaks if the whole text is enclosed in <p></p>. In other words, the question would be:

How do I tell the YUI Editor to enclose the whole text in the textarea with <p></p>?

+4  A: 

Looks like you want the "ptags" configuration option:

var myEditor = new YAHOO.widget.Editor('msgpost', {
    height: '300px',
    width: '522px',
    dompath: true, //Turns on the bar at the bottom
    animate: true, //Animates the opening, closing and moving of Editor windows
    ptags: true
});
myEditor.render();

As documented here.

andynormancx
Thanks a lot! You made my day! :)
Javier
Though...if I delete the text in the textbox and paste a new one, it doesn't automatically enclose all of it with "ptags". Any idea how to do this? Pasted text should by default be in one big "ptag".
Javier
Can't you just check the when you get the text out that it has "<p><p>" at the front and if it doesn't enclose the text with your extra p tags ?
andynormancx
Yes, but I need to do this before the user submits the text, so my CSS magic works. I could do this using javascript, but I hoped there would be a way to avoid javascript coding (the whole implementation is made on rails using the yui_editor plugin).
Javier