1

Topic: preserving line breaks with tinyMCE

Hi guys,

Here's my problem: I need tinyMCE to preserve line breaks - it is currently converting line breaks into a paragraph end (</p>). Is there a way to make tinyMCE recognise only double line breaks as a paragrah? I want to keep the text formatting "as-is" entered by the user, line breaks being converted to br tags and double line breaks being converted into p tags on rendering.

On the same topic, is there an option to auto-detect and format URLs in the text? I had a look at the FAQ (http://tinymce.moxiecode.com/tinymce/docs/faq.html) but that does not really answer my question. I tried:

...
relative_urls : false,
convert_urls : true
...

but that did not seem to work.

Here's my init:

tinyMCE.init({
    mode : "exact",
    elements : "realcom",
    theme : "advanced",
    plugins : "",
    content_css : "/~interfaces/spot/tinyMCE.css",
    theme_advanced_toolbar_location : "top",
    theme_advanced_path_location : "bottom",
    theme_advanced_resize_horizontal : false,
    theme_advanced_resizing : true,
    theme_advanced_layout_manager : "SimpleLayout",
    theme_advanced_buttons1 : "bold,italic,image,link,unlink",
    theme_advanced_buttons2 : "",
    relative_urls : false,
    convert_urls : true
});

2

Re: preserving line breaks with tinyMCE

You can set: remove_linebreaks : false in the init of tinymce to avoid that tinymce removes the linebreaks.

You can convert urls yourself by creating your own urlconverter callback function like this:

function myCustomURLConverter(url, node, on_save) {
    // Do some custom URL convertion
    url = url.substring(3);

    // Return new URL
    return url;
}

tinyMCE.init({
    ...
    urlconverter_callback : "myCustomURLConverter"
});

3

Re: preserving line breaks with tinyMCE

thanks! I got some php code to do the url conversion already but to be able to do it in js might be handy. As for the remove_linebreaks : false, it works fine, except now tinyMCE inserts <br /> tags into my code.

Is there a way to replace those br tags with standard linebreak characters like \r\n? should I just re-enable remove_linebreaks and change something else?

What I want is for tinyMCE to leave the text entered as it is without changing it on submition - that is, respect linebreaks, no putting <p> and <br /> tags everywhere, etc...I got some php code already doing that. What I want tinyMCE to be managing are just anchors and images.

Hope this makes some sense smile

Thanks for the great help so far!

Last edited by laurenth (2007-01-09 02:40:33)

4

Re: preserving line breaks with tinyMCE

Maybe it works if you use the following options in tinymce.init()

force_p_newlines : false
force_br_newlines : false

or you can try to set:

cleanup : false

Dont know if it helps. What you can do also is change <br> to \r using php and the replace function.

5

Re: preserving line breaks with tinyMCE

It almost works now - I got it to keep the linebreaks and not to insert <p> tags everywhere. What I can't seem to get rid of though are the <br /> tags. Weird. Here is my init:

tinyMCE.init({
    mode : "exact",
    elements : "realcom",
    theme : "advanced",
    plugins : "",
    content_css : "/~interfaces/spot/tinyMCE.css",
    theme_advanced_toolbar_location : "top",
    theme_advanced_path_location : "bottom",
    theme_advanced_resize_horizontal : false,
    theme_advanced_resizing : true,
    theme_advanced_layout_manager : "SimpleLayout",
    theme_advanced_buttons1 : "bold,italic,image,link,unlink",
    theme_advanced_buttons2 : "",
    remove_linebreaks : false, //<-- working, isn't it set to false by default??
    force_br_newlines : false, //<-- not working sad
    force_p_newlines : false, //<-- seems to be working fine
    verify_html : false //<-- not sure what this does...
});

Maybe there is some kind of stacking order which needs to be respected?

And what would cleanup : false do exactly??

6

Re: preserving line breaks with tinyMCE

Hi!

I think there is a misunderstanding here!

If you would like to keep your "linebreaks" in the source code then I don't know of a really satisfying solution. Try the apply_source_formatting option. TinyMCE isn't exactly a code editor and as such doesn't structure the source code all to reader-friendly...

laurenth wrote:

Maybe there is some kind of stacking order which needs to be respected?

Absolutely not.

laurenth wrote:

And what would cleanup : false do exactly??

It does exactly nothing. If it were set to true it would check wether the HTML elements and their attributes used in the code are allowed elements/attributes as set in the configuration and it would also remove any </tag>s where there isn't a corresponding <tag> or in turn close tags which haven't been closed.

Greetings from Germany,

Felix Riesterer.

Greetings from Germany,

Felix Riesterer.
(-> about me and this forum <-)

7

Re: preserving line breaks with tinyMCE

Thanks, I'm going to try that!

8

Re: preserving line breaks with tinyMCE

I'd like to mention here, for the completely confused (like I was), that you can convert P to BR by setting:

forced_root_block : false,
force_br_newlines : true,
force_p_newlines : false,    
convert_newlines_to_brs : true

Okay, fine, your P's become BR's. But then read this:

http://wiki.moxiecode.com/index.php/Tin … lements.3F

And what I discovered was that if I selected text, the indent, outdent buttons no longer worked after I made this change. Frustrating!

The fix was to start with this in your Init:

forced_root_block : true,
force_br_newlines : false,
force_p_newlines : true,    
convert_newlines_to_brs : false

And the CSS you need to edit is in this path (if using advanced):

tiny_mce/themes/advanced/skins/default/content.css

At the top of that file, just add this line:

P {
    margin: 0;
    padding: 0;
}

But please clear your cache because I found that even on Linux with FF3, the CSS was cached somehow and I had to clear private data to clear the browsing history and temporary files, and then the P change in the CSS worked.

Last edited by volomike (2008-12-10 02:46:33)

9

Re: preserving line breaks with tinyMCE

Thanks, this is great. I have a problem with styles though, I get additional lines with punbb plugin right after "quote"... a new line is added every time I edit a post