4

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>?

Javier
  • 2,491
  • 4
  • 36
  • 57

1 Answers1

6

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
  • 13,421
  • 6
  • 36
  • 52
  • 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 Mar 04 '09 at 10:11
  • Can't you just check the when you get the text out that it has "

    " at the front and if it doesn't enclose the text with your extra p tags ?

    – andynormancx Mar 04 '09 at 10:27
  • 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 Mar 04 '09 at 10:34