edit html in tinymce does not convert \n to line breaks - tinymce

When i set the content to 'a\nb' in tinymce, the edit in html shows 'ab', and when i set it again, through console. it shows as
a
b
why could this be happening? and how to fix it?

This might be because of of the cleanup functionality of tinymce. Using html will yield html without tinymce internal elements/attributs and cleaned content.

Related

Iframes converted to image tags in TinyMCE inline mode

I have a content management system that uses TinyMCE to edit text, and I am using the inline option. The issue I have is when the content contains an iframe - when TinyMCE is initialised, it converts the iframes to an image tag:
<img data-mce-p-allowfullscreen="allowfullscreen" data-mce-p-frameborder="0" data-mce-p-src="https://www.youtube.com/embed/xxxxx" width="560" height="315" src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" data-mce-object="iframe" class="mce-object mce-object-iframe" data-mce-src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7">
I then need to get the edited HTML to save to the server. The docs for this functionality give no suggestion on how to do this, so currently I use jQuery to just get the HTML content of the element the TinyMCE editor was initialised on, however this contains the image tag instead of the original iframe, which is what then gets saved.
Is there a better way to get the HTML from n inline TinyMCE instance, or change how TinyMCE displays iframes?
Here is a TinyMCE Fiddle that shows TinyMCE running inline with an iFrame in the content. When I use getContent() to extract the content it just shows as an iFrame.
http://fiddle.tinymce.com/rkgaab
As a rule of thumb I would not use jQuery to try to get the raw HTML as TinyMCE does a variety of things to accommodate for how inline editing works. The getContent() API is documented here:
https://www.tinymce.com/docs/api/tinymce/tinymce.editor/#getcontent

TinyMCE won't wrap html comments in a <p>

...and this is correct behavior but where is this file with this setting in TinyMCE 3.4.7 (in modx Revolution 2.2.6 it's TinyMCE 4.3.3)?
Is it possible to add some other exceptions? For example if I want everything be wrapped in p except img, etc.?
You can configure what is valid and what is not. For this check the tinymce configuration parameters valid_elements, valid_children and extended_valid_elements.

htmlPurifier not working with TinyMCE

I´m using htmlPurifier to prevent XSS Attacks from users and everything works ok on input type="text" fields. But, when i try to clean tinyMCE textareas seems like htmlPurifier don´t work, ex.:
Simple input text field
Input.:
<script>alert("XSS")</script>Cleaning Test
Output: Cleaning Test
tinyMCE TEXTAREA
Input.:
<script>alert("XSS")</script>
Output: <script>alert("XSS")</script>
Did i miss something ? Why htmlPurifier work on a simple input text and with tinyMCE textarea don´t ?
Ps.: Magic Quotes are Off
I think i found what was wrong.
tinyMCE automatically encode entities such:
< into <
> into >
" into "
& into &
I tried to use diferent types of entity_encoding on tinyMCE but none of them seems to work as i want, so i used PHP: html_entity_decode to decode tinyMCE text area and then i used htmlPurifier to sanitize the data and everything works ok now.
Hope someone else find this usefull.
You will need to call tinymce.triggerSave() in order to write the tinymce content back to the tinymce source element (can be a textarea) before the purifier can work.

Tinymce initizlising textarea with <> tags

Tinymce editor is not rendering editor properly when the content is something like
<textarea><p><sample data></p></textarea>
i.e. <sample data>.
When I initialize a TinyMCE editor here, I dont see anything as it looks like it assumes <sample data> is an HTML tag.
Please assume I have tinymce.js loaded and I initilize using tinymce.init.
Is there a fix for this? Please let me know if it is a server side fix, or is there a tinymce.init option I could give to fix this problem.
PS: It does look like this is an HTML Entity encoding related issue but I am hardly an expert in this area.
Have a look at the tinymce config parameter entity_encoding.
If this does not work you may use this workaround
// save content
var saved_content = document.getElementById('id_of_my_textarea').innerHTML;
// init the editor
tinyMCE.execCommand('mceAddControl', false, 'id_of_my_textarea');
// after tinymce is fully initialized do
// you should use the tinymce configuration parameter "setup" rather than this code here
tinymce.get('id_of_my_textarea').setContent(saved_content);

Tinymce - problem with fontsize using bbcodes

i am using tinymce with the bbcodes-plugin. In generally, its working nicely, most of the bbcodes like [b] and [color] and so forth are transmitted into html within the textarea and safed as bbcodes into the database correctly.
The thing with font-size is the following, when formating a string the first time it is correctly changing its size and is safed correctly as bbcode into the database.
But when i open that record again to edit it, the bbcode is not converted to html, so in the textarea there is something like
"[size= medium]rfeferf[/size]" instead of the text in the right size.
Do you have any hints on this? Ive been searching the web yesterday and today, didnt find anything that could solve this.
Regards, Maschek
This is caused by BBCode plugin in TinyMCE unable to transform [size] tag back to HTML. I've logged a TinyMCE bug #5327 with a fix patch attached. You can download latest TinyMCE source, apply the patch and compile it (or wait until the patch is reviewed and released).
The related source code is located at plugins/bbcode/editor_plugin_src.js