You are not logged in.
#1 2007-01-08 03:04:30
- laurenth
- Member
- Registered: 2007-01-04
- Posts: 6
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
});
Offline
#2 2007-01-08 15:33:20
- rcjkierkels
- Member
- Registered: 2005-12-02
- Posts: 47
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:
Code:
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"
});Offline
#3 2007-01-09 01:39:58
- laurenth
- Member
- Registered: 2007-01-04
- Posts: 6
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 ![]()
Thanks for the great help so far!
Last edited by laurenth (2007-01-09 01:40:33)
Offline
#4 2007-01-09 09:14:09
- rcjkierkels
- Member
- Registered: 2005-12-02
- Posts: 47
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.
Offline
#5 2007-01-10 04:03:12
- laurenth
- Member
- Registered: 2007-01-04
- Posts: 6
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 ![]()
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??
Offline
#6 2007-01-10 05:28:47
- Felix Riesterer
- Administrator
- From: Germany
- Registered: 2005-12-30
- Posts: 4601
- Website
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.
Offline
#7 2007-01-11 08:30:23
- laurenth
- Member
- Registered: 2007-01-04
- Posts: 6
Re: preserving line breaks with tinyMCE
Thanks, I'm going to try that!
Offline
#8 2008-12-10 01:32:49
- volomike
- Member
- Registered: 2008-08-25
- Posts: 14
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:
Code:
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:
Code:
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:
Code:
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 01:46:33)
Offline
© 2003-2010